w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
python fabric - passing host as arguemnt
./fabfile.py
from fabric.api import run, env

env.user = "root"
env.key_filename = "/home/ubuntu/.ssh/id_rsa"
def test():
    run("mkdir -p /home/ubuntu/")

---
fabric:~$ fab test -H 111.111.111.111
>>>[192.168.99.20] Executing task 'test'
>>>[192.168.99.20] run: mkdir -p /home/ubuntu/
>>>
>>>Done.

[-H] opstion sets env.hosts to the given comma-delimited list of host strings. Please check here for detailed fab command usag

or like this.

./fabfile.py
def setenv(host=None):
    if host is not None:
        env.hosts= [host]
    env.user = "ubuntu"
    env.key_filename = "/home/ubuntu/.ssh/id_rsa"

def test():
    run("mkdir -p /home/ubuntu/")

---
fabric:~$ fab setenv:web01 test
(snip)




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.