__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. # Explorer will output the key if he exists.
secretkey="/opt/netbox/.secretkey" secretkey="/opt/netbox/cdist/secretkey"
if [ -f "$secretkey" ]; then if [ -f "$secretkey" ]; then
cat "$secretkey" cat "$secretkey"
fi fi

View file

@ -1,5 +1,5 @@
#!/bin/sh -e #!/bin/sh -e
# output version if exist # 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 if [ -f "$version_path" ]; then cat "$version_path"; fi

View file

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

View file

@ -194,20 +194,23 @@ mkdir -p "$__object/files"
"$__type/files/configuration.py.sh" > "$__object/files/configuration.py" "$__type/files/configuration.py.sh" > "$__object/files/configuration.py"
"$__type/files/ldap_config.py.sh" > "$__object/files/ldap_config.py" "$__type/files/ldap_config.py.sh" > "$__object/files/ldap_config.py"
require="__user/netbox" __directory /opt/netbox/netbox/cdist --parents require="__user/netbox" __directory /opt/netbox/cdist
require="__directory/opt/netbox/netbox/cdist " __file \ require="__directory/opt/netbox/cdist" __file \
/opt/netbox/netbox/cdist/configuration.py --mode 640 --owner netbox \ /opt/netbox/cdist/configuration.py --mode 640 --owner netbox \
--source "$__object/files/configuration.py" --source "$__object/files/configuration.py"
if [ -f "$__object/parameter/ldap-server" ]; then if [ -f "$__object/parameter/ldap-server" ]; then
require="__directory/opt/netbox/netbox/cdist " __file \ require="__directory/opt/netbox/cdist" __file \
/opt/netbox/netbox/cdist/ldap_config.py --mode 640 --owner netbox \ /opt/netbox/cdist/ldap_config.py --mode 640 --owner netbox \
--source "$__object/files/ldap_config.py" --source "$__object/files/ldap_config.py"
else
require="__directory/opt/netbox/cdist" __file \
/opt/netbox/cdist/ldap_config.py --state absent
fi fi
# save secret # save secret
require="__user/netbox" __file /opt/netbox/.secretkey --mode 400 \ require="__directory/opt/netbox/cdist" __file /opt/netbox/cdist/secretkey \
--owner netbox --source - << SECRET --mode 400 --owner netbox --source - << SECRET
$SECRET_KEY $SECRET_KEY
SECRET SECRET