__netbox: adding seperate /opt/netbox/cdist/ directory

Adding a place to keep all configuration stuff for cdist seperated from
the installation directory. For safety reasons.
This commit is contained in:
matze 2020-09-28 19:49:29 +02:00
parent e800f42a6d
commit b55186544f
4 changed files with 19 additions and 28 deletions

View File

@ -2,7 +2,7 @@
# Explorer will output the key if he exists.
secretkey="/opt/netbox/.secretkey"
secretkey="/opt/netbox/cdist/secretkey"
if [ -f "$secretkey" ]; then
cat "$secretkey"
fi

View File

@ -1,5 +1,5 @@
#!/bin/sh -e
# output version if exist
version_path="/opt/netbox/netbox/cdist/version"
version_path="/opt/netbox/cdist/version"
if [ -f "$version_path" ]; then cat "$version_path"; fi

View File

@ -24,16 +24,13 @@ cd "\$tmpdir"
curl -sS -L '$url' > '$archive'
tar xf '$archive'
# Save cdist-upload configuration file.
cp '$install_dir/cdist/configuration.py' "\$tmpdir/configuration.py"
cp '$install_dir/cdist/ldap_config.py' "\$tmpdir/ldap_config.py"
EOF
# Stop everything in the pyenv to update
cat << EOF
# Try to kill everything in the venv
systemctl stop netbox gunicorn-netbox uwsgi-netbox || true
systemctl -q --wait stop netbox gunicorn-netbox uwsgi-netbox || true
# don't know if this is required since using --wait
ps -axo pid,cmd | awk '\$2 ~ "^/opt/netbox/venv/"{print \$1}' | xargs kill || true
EOF
@ -42,11 +39,10 @@ EOF
# Deploy sources and restore configuration.
rm -r '$install_dir'
cp -r '$src/netbox' '$install_dir'
mkdir '$install_dir/cdist'
cp '$src/requirements.txt' /opt/netbox/ # backup dependency info
cp \$tmpdir/configuration.py '$install_dir/netbox/configuration.py'
cp \$tmpdir/ldap_config.py '$install_dir/netbox/ldap_config.py'
ln -s /opt/netbox/cdist/configuration.py '$install_dir/netbox/configuration.py'
ln -s /opt/netbox/cdist/ldap_config.py '$install_dir/netbox/ldap_config.py'
# Setup & enter python virtualenv.
# forcing python3 to be sure (till python4 gets released ..)
@ -79,24 +75,16 @@ cd /
rm -r "\$tmpdir"
# Save version after successful installation
printf "%s\\n" "$VERSION" > '$install_dir/cdist/version'
printf "%s\\n" "$VERSION" > /opt/netbox/cdist/version
EOF
# meta
printf "installed %s\n" "$VERSION" >> "$__messages_out"
changes=yes
fi
# check if configuration changed
elif grep -q "^__file/opt/netbox/" "$__messages_in"; then
# check if coping is required
if grep -q "^__file/opt/netbox/netbox/cdist/" "$__messages_in"; then
cat << EOF
# Copy configuration
cp '$install_dir/cdist/configuration.py' '$install_dir/netbox/configuration.py'
cp '$install_dir/cdist/ldap_config.py' '$install_dir/netbox/ldap_config.py'
EOF
fi
if grep -q "^__file/opt/netbox/" "$__messages_in"; then
# meta
printf "configured\n" >> "$__messages_out"
changes=yes

View File

@ -194,20 +194,23 @@ mkdir -p "$__object/files"
"$__type/files/configuration.py.sh" > "$__object/files/configuration.py"
"$__type/files/ldap_config.py.sh" > "$__object/files/ldap_config.py"
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 \
require="__user/netbox" __directory /opt/netbox/cdist
require="__directory/opt/netbox/cdist" __file \
/opt/netbox/cdist/configuration.py --mode 640 --owner netbox \
--source "$__object/files/configuration.py"
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 \
require="__directory/opt/netbox/cdist" __file \
/opt/netbox/cdist/ldap_config.py --mode 640 --owner netbox \
--source "$__object/files/ldap_config.py"
else
require="__directory/opt/netbox/cdist" __file \
/opt/netbox/cdist/ldap_config.py --state absent
fi
# save secret
require="__user/netbox" __file /opt/netbox/.secretkey --mode 400 \
--owner netbox --source - << SECRET
require="__directory/opt/netbox/cdist" __file /opt/netbox/cdist/secretkey \
--mode 400 --owner netbox --source - << SECRET
$SECRET_KEY
SECRET