$FHHOME/fabfile/example.py
$ fab -l |grep example. $ fab -H host1,host2 ope.check_user01
fab -H host1,host2 -- hostname fab -H host1,host2 -- sudo cat /etc/shadow
$FHHOME/fabfile/example.py
import sys, os from fabric.api import * from fabric.contrib import files from fabric.operations import open_shell FHHOME=os.environ["FHHOME"] @task def change_group_user01(): run("hostname") run("id user01") sudo("sed -i.20180304 's/^user01/dev/' /etc/group") run("diff /etc/group /etc/group.20180304") run("id user01") @task def change_group_user01_reverse(): run("hostname") run("id user01") sudo("\cp -pf /etc/group.20180304 /etc/group" ) run("id user01")
from fabric.colors import * def color(): print 'aaaaa' print blue('blue') + ' color' print cyan('cyan') + ' color' print green('green') + ' color' print magenta('magenta') + ' color' print red('red') + ' color' print white('white') + ' color' print yellow('yellow') + ' color' print (red("This sentence is red, except for " + green("these words, which are green") + "."))
def startTomcat(): run('/etc/init.d/tomcat start < /dev/null > /dev/null 2> /dev/null', pty=False, timeout = 60)
Related Pages