Hello everyone,
My server networking is as follows:
Load Balancer
|
|__Apache2 Server -1
|
|__Apache2 Server -2
|
|__Apache2 Server -3
|
|__Apache2 Server -..n
My problem is this: When I make a change or update to my software, I reinstall the update on all my servers one by one. Or when there is an bug, it is very tiring to fix the error one by one. Do you have an application or an alternative suggestion that will send it to all servers at the same time when I make a change in the software codes?
Note: I'm not looking for a very complex application. I'm looking for an application that will simultaneously send my software files to just the ip addresses I want.
Ansible and puppet are a bit complicated.
This is a simple utility I wrote some years ago, for my specific needs:
#!/bin/bash
#####################################################################
#
# call this script appending a command to be executed on all servers
#
#####################################################################
if [[ $# -eq 0 ]]; then
echo "No command specified"
exit 2
fi
# server ip, or DNS name
declare -a my_servers=("xxx.xxx.xxx.xxx" "yyy.yyy.yyy.yyy" "zzz.zzz.zzz.zzz")
remote_cmd="$1"
#start loop
for server in ${my_servers[@]};
do
echo -e "\n\n\n-----------------------------------> $server: <--------------------------------------------------------------\n\n"
ssh -i /root/.ssh/my_specific_key_rsa -p 5678 root@$server " hostnamectl | head -n 1 ; $remote_cmd ; exit"
done
exit
Assuming you called it sysadmin_helper.sh
, after giving execution permissions you can do things like:
sysadmin_helper.sh 'reboot'
sysadmin_helper.sh 'df -h /'
sysadmin_helper.sh 'systemctl reload apache2'
sysadmin_helper.sh 'tail /var/log/apache2/error.log' ...
And so on, greatly speeding up your work.
Coming to your main question, maybe you can do:
sysadmin_helper.sh 'cd $my_repo_dir ; git pull '
, or whatever you use for a sync with a git server.
For this script to work, you need therefore:
my_servers
var and the exact path of your ssh keyAnyway, there are many ways to adapt this script to your needs.
Disclaimer: I'm not an IT security specialist, and not even a pro in this area. So, any corrections or improvements are welcome.