author: headsen chen
date: 2018-08-12 23:13:16
1,安装
yum -y install epel-release
yum -y install fabric
2,指定密码的使用:
fab -p 123456 -H 192.168.10.10 -f f1.py w
#cat f1.py
#!/usr/bin/env python from fabric.api import run def w(): run('w')
确定:当指定的密码不正确的时候,会一直让你尝试输入密码
3,通过定义的密码文件来执行fab命令
[root@localhost mnt]# vim f2.py
#!/usr/bin/env python # -*- coding:utf-8 -*- from fabric.api import * env.hosts = ['192.168.10.104','192.168.10.105','192.168.10.101'] env.port = '22' env.user = 'root' env.password = '123456' def a(): with cd('/tmp'): run('touch a{1..10}') run('ls /tmp') def b(): run('uptime') @task def go(): a() b()
[root@localhost mnt]# fab -f f2.py go
[192.168.10.104] Executing task 'go' [192.168.10.104] run: touch a{1..10} [192.168.10.104] run: ls /tmp [192.168.10.104] out: a1 a10 a2 a3 a4 a5 a6 a7 a8 a9 yum.log [192.168.10.104] out: [192.168.10.104] run: uptime [192.168.10.104] out: 05:21:33 up 57 min, 3 users, load average: 0.00, 0.00, 0.00 [192.168.10.104] out: [192.168.10.105] ... [192.168.10.101] ... Done. Disconnecting from 192.168.10.101... done. Disconnecting from 192.168.10.104... done. Disconnecting from 192.168.10.105... done.