fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Update multiple files and just backup once


From: Carlos García
Subject: Re: [Fab-user] Update multiple files and just backup once
Date: Wed, 14 Dec 2016 17:47:46 +0100

Hi Randal,

the task is being executed on each host you put in -H, that’s why the backup is done 3 times. In order to avoid this, I think the easiest way is to use execute(). (BTW, I’m not really sure what are you doing in backup)

def backup_and_upload():
  execute(backup)
  execute(upload, hosts=['server1',''server2', 'server3'])

def upload():
  conf_files = current_dir + 'abc.conf'
  remote_conf_dir = '/etc/abc/'
  put(conf_files, remote_conf_dir, use_sudo=True)
  print(green("Upload complete"))

You can run this locally (fab backup_and_upload -H localhost), as execute() will connect to hosts to perform the task.

This will work, but maybe later you will need to add more servers. In that case, you can use parameters or try a more dynamic approach. Read this, is a must! http://docs.fabfile.org/en/1.12/usage/execution.html

Regards

2016-12-14 17:34 GMT+01:00 Randal Ray <address@hidden>:

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



_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user


reply via email to

[Prev in Thread] Current Thread [Next in Thread]