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.
#!/bin/bash # 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
#!/bin/bash #installs git and saltmaster&minion sets keyboard to fi cd 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 https://github.com/aksratamo/salt 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: http://terokarvinen.com/2018/aikataulu-%E2%80%93-palvelinten-hallinta-ict4tn022-3004-ti-ja-3002-to-%E2%80%93-loppukevat-2018-5p#h4
Used as help: https://github.com/terokarvinen/sirotin
Used as help: https://github.com/jisosomppi/log-analysis/tree/master/salt
Copyright GPLv2 2018