Randal Ray
2016-12-14 16:34:24 UTC
Hi everyone,
I've recently started using Fabric. I have multiple 3 web servers. The specification of SSH options such as HostName and User are saved in $HOME/.ssh/config, which looks like this:
Host server1
HostName 54.xxx.yyy.zzz
User ubuntu
Host server2
HostName 54.aaa.bbb.ccc
User ubuntu
Host server3
HostName 54.ddd.eee.fff
User ubuntu
Now I would like to update a file on each of these 3 servers (the content of these files are the same) with a local file.
My fabfile looks like this:
env.use_ssh_config = True
def upload():
execute(backup)
conf_files = current_dir + 'abc.conf'
remote_conf_dir = '/etc/abc/'
put(conf_files, remote_conf_dir, use_sudo=True)
print(green("Upload complete"))
When I run `fab -H server1, server2, server3 upload`, this script will backup the file three times.
Because the content of these 3 files are the same, I want to backup just one copy of the file on my local machine at first, then update all 3 of them.
My first thought was to read the ssh config file into a list and iterate the list, do things on the first server, then break the loop. I felt this seemed a bit hokey to find.
Is there any other way to implement this? I've searched Google and Stackoverflow, but I got nothing about this.
Your help would be appreciated!
Vincent
I've recently started using Fabric. I have multiple 3 web servers. The specification of SSH options such as HostName and User are saved in $HOME/.ssh/config, which looks like this:
Host server1
HostName 54.xxx.yyy.zzz
User ubuntu
Host server2
HostName 54.aaa.bbb.ccc
User ubuntu
Host server3
HostName 54.ddd.eee.fff
User ubuntu
Now I would like to update a file on each of these 3 servers (the content of these files are the same) with a local file.
My fabfile looks like this:
env.use_ssh_config = True
def upload():
execute(backup)
conf_files = current_dir + 'abc.conf'
remote_conf_dir = '/etc/abc/'
put(conf_files, remote_conf_dir, use_sudo=True)
print(green("Upload complete"))
When I run `fab -H server1, server2, server3 upload`, this script will backup the file three times.
Because the content of these 3 files are the same, I want to backup just one copy of the file on my local machine at first, then update all 3 of them.
My first thought was to read the ssh config file into a list and iterate the list, do things on the first server, then break the loop. I felt this seemed a bit hokey to find.
Is there any other way to implement this? I've searched Google and Stackoverflow, but I got nothing about this.
Your help would be appreciated!
Vincent