0

I want to run different command on the different pc group. my fabric file like following:

env.hosts = ['125.221.225.31','125.221.225.36','125.221.225.33','125.221.225.34','125.221.225.35']
env.roledefs = {
    'master':['125.221.225.31'],
    'slave':['125.221.225.33','125.221.225.34','125.221.225.35','125.221.225.36']}

@roles('master')
def get_last_hosts():
    with cd('/etc'):
        get('hosts','/tmp/hosts')

@roles('slave')
def upload_hosts():
    with lcd('/tmp'):
        put('hosts','/etc/hosts',use_sudo=True)

def update_hosts():
    get_last_hosts()
    upload_hosts()

I can run:

fab get_last_hosts,

and then run:

fab upload_hosts 

I want to merge these steps to one step, so to say:

update_hosts

but that won't work, it will run update_hosts on every pc in the env.hosts, that's not what I desire.

oz123
  • 27,559
  • 27
  • 125
  • 187
kuafu
  • 1,466
  • 5
  • 17
  • 28

1 Answers1

1

You can get around this by using the execute command. In something like this:

def update_hosts():
    execute(get_last_hosts)
    execute(upload_hosts)
Morgan
  • 4,143
  • 27
  • 35