新建脚本文件 fabmkdir.py,
from fabric.api import *
from fabric.colors import *
env.roledefs = {
'slave1server':['root@slave1',],
'slave2server':['root@slave2',],
'slave3server':['root@slave3',]
}
#env.password = '123456'
@roles('slave1server')
def test():
with cd('/usr'):
run('mkdir A0124')
run('ls -lh')
执行脚本 fab -f fabmkdir
.py test
[root@master ~]# fab -f fabmkdir.py test
[root@slave1] Executing task 'test'
[root@slave1] run: mkdir A0124
[root@slave1] run: ls -lh
[root@slave1] out: 总用量 22M
[root@slave1] out: drwxr-xr-x. 2 root root 6 1月 24 15:31 A0124
[root@slave1] out: dr-xr-xr-x. 2 root root 16K 1月 19 11:13 bin
[root@slave1] out: drwxr-xr-x. 2 root root 6 8月 12 2015 etc
[root@slave1] out: drwxr-xr-x. 2 root root 6 8月 12 2015 games
[root@slave1] out: drwxr-xr-x. 15 root root 4.0K 11月 26 16:26 hadoop
[root@slave1] out: drwxr-xr-x. 9 root root 4.0K 10月 19 11:23 hbase
[root@slave1] out: drwxr-xr-x. 3 root root 22 10月 16 17:35 include
[root@slave1] out: drwxr-xr-x. 5 root root 51 11月 24 10:45 java
[root@slave1] out: drwxr-xr-x. 3 root root 24 10月 17 11:46 java_bak
[root@slave1] out: dr-xr-xr-x. 26 root root 4.0K 10月 16 17:36 lib
[root@slave1] out: dr-xr-xr-x. 40 root root 20K 1月 19 11:13 lib64
[root@slave1] out: drwxr-xr-x. 15 root root 4.0K 10月 28 16:40 libexec
[root@slave1] out: drwxr-xr-x. 12 root root 4.0K 10月 16 17:34 local
[root@slave1] out: dr-xr-xr-x. 2 root root 12K 10月 28 16:40 sbin
[root@slave1] out: drwxrwxr-x. 6 root root 46 10月 28 11:08 scala
[root@slave1] out: drwxr-xr-x. 71 root root 4.0K 10月 16 17:37 share
[root@slave1] out: drwxr-xr-x. 17 root root 4.0K 11月 10 17:59 spark
[root@slave1] out: drwxr-xr-x. 4 root root 32 10月 16 17:34 src
[root@slave1] out: drwxr-xr-x. 3 root root 19 1月 18 11:54 storm1.0.0
[root@slave1] out: drwxr-xr-x. 14 root root 4.0K 1月 18 13:58 storm1.1.1
[root@slave1] out: lrwxrwxrwx. 1 root root 10 10月 16 17:34 tmp -> ../var/tmp
[root@slave1] out: drwxr-xr-x. 13 1000 1000 4.0K 1月 24 15:02 zookeeper
[root@slave1] out: -rw-r--r--. 1 root root 22M 2月 22 2016 zookeeper-3.4.8.tar.gz
[root@slave1] out:
Done.
Disconnecting from slave1... done.
[root@master ~]#