cdist-contrib/type/__netbox/manifest

89 lines
2.8 KiB
Plaintext
Raw Normal View History

2020-07-20 15:20:33 +00:00
#!/bin/sh
os=$(cat "$__global/explorer/os")
case "$os" in
debian|ubuntu)
# Install netbox dependencies.
for pkg in python3-pip python3-venv python3-dev build-essential libxml2-dev \
libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev curl virtualenv; do
__package $pkg
done
2020-07-21 05:46:45 +00:00
if [ -f "$__object/parameter/ldap-server" ]; then
for pkg in libldap2-dev libsasl2-dev libssl-dev; do
__package $pkg
done
fi
2020-07-20 15:20:33 +00:00
;;
*)
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "$os" "${__type##*/}" >&2
printf "Please contribute an implementation for it if you can.\n" >&2
exit 1
;;
esac
export DATABASE_NAME=$(cat "$__object/parameter/database")
export DATABASE_PASSWORD=$(cat "$__object/parameter/database-password")
export ALLOWED_HOST=$(cat "$__object/parameter/host")
export SECRET_KEY=$(cat "$__object/parameter/secret-key")
2020-07-21 05:46:45 +00:00
if [ -f "$__object/parameter/ldap-server" ]; then
export LDAP_SERVER=$(cat "$__object/parameter/ldap-server")
fi
if [ -f "$__object/parameter/ldap-bind-dn" ]; then
export LDAP_BIND_DN=$(cat "$__object/parameter/ldap-bind-dn")
fi
if [ -f "$__object/parameter/ldap-bind-password" ]; then
export LDAP_BIND_PASSWORD=$(cat "$__object/parameter/ldap-bind-password")
fi
if [ -f "$__object/parameter/ldap-user-base" ]; then
export LDAP_USER_BASE=$(cat "$__object/parameter/ldap-user-base")
fi
if [ -f "$__object/parameter/ldap-group-base" ]; then
export LDAP_GROUP_BASE=$(cat "$__object/parameter/ldap-group-base")
fi
if [ -f "$__object/parameter/ldap-require-group" ]; then
export LDAP_REQUIRE_GROUP=$(cat "$__object/parameter/ldap-require-group")
fi
if [ -f "$__object/parameter/ldap-superuser-group" ]; then
export LDAP_SUPERUSER_GROUP=$(cat "$__object/parameter/ldap-superuser-group")
2020-07-21 05:46:45 +00:00
fi
2020-07-20 15:20:33 +00:00
# Create system user used to run netbox.
__user netbox --system --home /opt/netbox --create-home
# Generate and upload netbox configuration.
mkdir -p "$__object/files"
"$__type/files/configuration.py.sh" > "$__object/files/configuration.py"
2020-07-21 05:46:45 +00:00
"$__type/files/ldap_config.py.sh" > "$__object/files/ldap_config.py"
2020-07-20 15:20:33 +00:00
require="__user/netbox" __directory /opt/netbox/netbox/cdist --parents
require="__directory/opt/netbox/netbox/cdist " __file \
/opt/netbox/netbox/cdist/configuration.py --mode 640 --owner netbox \
--source "$__object/files/configuration.py"
2020-07-21 05:46:45 +00:00
if [ -f "$__object/parameter/ldap-server" ]; then
require="__directory/opt/netbox/netbox/cdist " __file \
/opt/netbox/netbox/cdist/ldap_config.py --mode 640 --owner netbox \
--source "$__object/files/ldap_config.py"
fi
2020-07-20 15:20:33 +00:00
# Upload systemd units and gunicorn configuration.
for unit in netbox netbox-rq; do
__systemd_unit $unit.service \
--source "$__type/files/$unit.service" \
--enablement-state enabled
2020-07-20 15:20:33 +00:00
done
# Python worker configuration.
require="__user/netbox" __file /opt/netbox/gunicorn.py \
--mode 644 --source "$__type/files/gunicorn.py"