salt-minion template/script

This commit is contained in:
Will Sinatra 2023-05-04 22:42:53 -04:00
parent 80d557fba2
commit 889e23568a
3 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,48 @@
#!/bin/ash
master=x.x.x.x
#Usage: pkgs 'htop tmux emacs' [update]
pkgs() {
if [ "$2" == "update" ]; then
apk update
fi
apk add $1
}
#Usage:
salt_minion() {
if [ -f /etc/salt/minion ]; then
cp /etc/salt/minion /etc/salt/minion.bak
fi
default_master=$(grep -E '^#master: salt$' /etc/salt/minion)
master_ip=$(grep -E '^master: (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' /etc/salt/minion)
master_fqdn=$(grep -E '^master: ([a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]\.)+[a-zA-Z]{2,}$' /etc/salt/minion)
if [ "$default_master" != "" ] && [ "$master_ip" == "" ] && [ "$master_fqdn" = "" ]; then
sed -i 's/^#master: salt$/master: '$master'/' /etc/salt/minion
elif [ "$master_ip" != "" ] || [ "$master_fqdn" != "" ]; then
sed -i 's/^master: .*$/master: '$master'/' /etc/salt/minion
fi
}
#Usage: enable_services default 'lighttpd rsyslog samba iptables'
enable_services() {
for service in $2; do
rc-update add $service $1
done
}
#Usage: change_services start 'lighttpd rsyslog samba iptables'
#Variables:
change_services() {
for service in $2; do
rc-service $service $1
done
}
pkgs "python3 grep salt-minion" true
salt_minion
enable_services default "salt-minion"
change_services start "salt-minion"

16
Tasks/salt_minion Normal file
View File

@ -0,0 +1,16 @@
#Usage:
salt_minion() {
if [ -f /etc/salt/minion ]; then
cp /etc/salt/minion /etc/salt/minion.bak
fi
default_master=$(grep -E '^#master: salt$' /etc/salt/minion)
master_ip=$(grep -E '^master: (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' /etc/salt/minion)
master_fqdn=$(grep -E '^master: ([a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]\.)+[a-zA-Z]{2,}$' /etc/salt/minion)
if [ "$default_master" != "" ] && [ "$master_ip" == "" ] && [ "$master_fqdn" = "" ]; then
sed -i 's/^#master: salt$/master: '$master'/' /etc/salt/minion
elif [ "$master_ip" != "" ] || [ "$master_fqdn" != "" ]; then
sed -i 's/^master: .*$/master: '$master'/' /etc/salt/minion
fi
}

View File

@ -0,0 +1,19 @@
Shell: '#!/bin/ash'
Script: Generated/setup-salt-minion.sh
Debug: false
Variables:
- Name: master
Value: "x.x.x.x"
Tasks:
- Path: Tasks/apk_pkgs
Invo:
- 'pkgs "python3 grep salt-minion" true'
- Path: Tasks/salt_minion
Invo:
- 'salt_minion'
- Path: Tasks/enable_services
Invo:
- 'enable_services default "salt-minion"'
- Path: Tasks/change_services
Invo:
- 'change_services start "salt-minion"'