Automatic Salt slave


Writing a bash script that will setup a Saltmaster and slave and running highstate automatically.
I build last week a working salt command on my Github I will continue working with it.

Suprise Side Quest

I was getting tired of always running vagrant desroy then vagrant up then vagrant ssh.
So I wrote a bash script to do it for me you can get it here. You just put it in your vagrant folder where the Vagrantfile is and run it when ever you want to reset your vagrant setup.

# this will destroy and put up vagrand again and ssh it straght back for fast salt testing.
# run this in your vagrant master in the same folder as Vagrantfile
echo "Vagrant destroy"
vagrant destroy 
echo "Vagrant up"
vagrant up 
echo "Vagrant ssh"
vagrant ssh 

Getting highstate automaticly with “sleep”

I had problems with running "sudo salt-keys -A" after the systemctl reset so fiddled around and added a 5 second sleep time on to my bash after "sudo systemctl restart salt-minion"and it worked!
Then I had the same problem running the "sudo salt '*' state.highstate" as it returned “no minions responded” so I added before that also 5 seconds so the minion had time to realize its no a slave.

After more testing the 5 seconds seems to work only sometimes. I added it to 10.

So here is my masterpiece
#installs git and saltmaster&minion sets keyboard to fi

echo "Updating packages..."
sudo apt-get update -qq >> /dev/null
echo "Installing git and salt..."
sudo apt-get install git salt-master salt-minion -y -qq >> /dev/null
echo "Cloning repository..."
cd /srv/
sudo git clone

echo "Writing salt settings to file and restarting salt-minion..."
sudo echo -e "master: localhost\nid: localminion" | sudo tee /etc/salt/minion
sudo systemctl restart salt-minion
echo "Adding minion to master"
sleep 5
sudo salt-key -A
sleep 10
echo "Running highstate"
sudo salt '*' state.highstate


School assignement H4:
Used as help:
Used as help:
Copyright GPLv2 2018

Leave a Replay