把fabfile.py另存为fabtest.py
[root@master ~]# mv fabfile.py fabtest.py
fabric执行脚本[root@master ~]# fab -f fabtest.py dotask
[root@slave1] Executing task 'task1'
[root@slave1] run: ls -l /usr
[root@slave1] out: 总用量 21868
[root@slave1] out: dr-xr-xr-x. 2 root root 16384 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 4096 11月 26 16:26 hadoop
[root@slave1] out: drwxr-xr-x. 9 root root 4096 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 4096 10月 16 17:36 lib
[root@slave1] out: dr-xr-xr-x. 40 root root 20480 1月 19 11:13 lib64
[root@slave1] out: drwxr-xr-x. 15 root root 4096 10月 28 16:40 libexec
[root@slave1] out: drwxr-xr-x. 12 root root 4096 10月 16 17:34 local
[root@slave1] out: dr-xr-xr-x. 2 root root 12288 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 4096 10月 16 17:37 share
[root@slave1] out: drwxr-xr-x. 17 root root 4096 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 4096 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 4096 1月 18 11:38 zookeeper
[root@slave1] out: -rw-r--r--. 1 root root 22261552 2月 22 2016 zookeeper-3.4.8.tar.gz
[root@slave1] out:
[root@slave1] run: df -kh
[root@slave1] out: 文件系统 容量 已用 可用 已用% 挂载点
[root@slave1] out: /dev/mapper/centos_bogon-root 36G 14G 22G 39% /
[root@slave1] out: devtmpfs 1.9G 0 1.9G 0% /dev
[root@slave1] out: tmpfs 1.9G 0 1.9G 0% /dev/shm
[root@slave1] out: tmpfs 1.9G 104M 1.8G 6% /run
[root@slave1] out: tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
[root@slave1] out: /dev/sda1 497M 125M 373M 25% /boot
[root@slave1] out: tmpfs 378M 0 378M 0% /run/user/0
[root@slave1] out:
[root@slave2] Executing task 'task2'
[root@slave2] run: ls -l /usr
[root@slave2] out: 总用量 128
[root@slave2] out: dr-xr-xr-x. 2 root root 16384 10月 18 16:10 bin
[root@slave2] out: drwxr-xr-x. 2 root root 6 8月 12 2015 etc
[root@slave2] out: drwxr-xr-x. 2 root root 6 8月 12 2015 games
[root@slave2] out: drwxr-xr-x. 15 root root 4096 11月 26 16:26 hadoop
[root@slave2] out: drwxr-xr-x. 9 root root 4096 10月 19 11:23 hbase
[root@slave2] out: drwxr-xr-x. 3 root root 22 10月 16 17:36 include
[root@slave2] out: drwxr-xr-x. 5 root root 51 11月 24 10:46 java
[root@slave2] out: drwxr-xr-x. 3 root root 24 10月 17 11:47 java_bak
[root@slave2] out: dr-xr-xr-x. 26 root root 4096 10月 16 17:37 lib
[root@slave2] out: dr-xr-xr-x. 40 root root 20480 10月 16 17:38 lib64
[root@slave2] out: drwxr-xr-x. 15 root root 4096 10月 28 16:41 libexec
[root@slave2] out: drwxr-xr-x. 12 root root 4096 10月 16 17:35 local
[root@slave2] out: dr-xr-xr-x. 2 root root 12288 10月 28 16:41 sbin
[root@slave2] out: drwxrwxr-x. 6 root root 46 10月 28 11:11 scala
[root@slave2] out: drwxr-xr-x. 71 root root 4096 10月 16 17:38 share
[root@slave2] out: drwxr-xr-x. 16 root root 4096 11月 10 17:59 spark
[root@slave2] out: drwxr-xr-x. 4 root root 32 10月 16 17:35 src
[root@slave2] out: drwxr-xr-x. 3 root root 19 1月 18 11:54 storm1.0.0
[root@slave2] out: drwxr-xr-x. 14 root root 4096 1月 18 13:57 storm1.1.1
[root@slave2] out: lrwxrwxrwx. 1 root root 10 10月 16 17:35 tmp -> ../var/tmp
[root@slave2] out: drwxr-xr-x. 14 root root 4096 1月 18 11:38 zookeeper
[root@slave2] out:
[root@slave2] run: df -kh
[root@slave2] out: 文件系统 容量 已用 可用 已用% 挂载点
[root@slave2] out: /dev/mapper/centos_bogon-root 36G 19G 18G 52% /
[root@slave2] out: devtmpfs 1.9G 0 1.9G 0% /dev
[root@slave2] out: tmpfs 1.9G 0 1.9G 0% /dev/shm
[root@slave2] out: tmpfs 1.9G 104M 1.8G 6% /run
[root@slave2] out: tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
[root@slave2] out: /dev/sda1 497M 125M 373M 25% /boot
[root@slave2] out: tmpfs 378M 0 378M 0% /run/user/0
[root@slave2] out:
[root@slave3] Executing task 'task3'
[root@slave3] run: ls -l /usr
[root@slave3] out: 总用量 124
[root@slave3] out: dr-xr-xr-x. 2 root root 16384 10月 18 16:10 bin
[root@slave3] out: drwxr-xr-x. 2 root root 6 8月 12 2015 etc
[root@slave3] out: drwxr-xr-x. 2 root root 6 8月 12 2015 games
[root@slave3] out: drwxr-xr-x. 15 root root 4096 11月 26 16:26 hadoop
[root@slave3] out: drwxr-xr-x. 9 root root 4096 10月 19 11:23 hbase
[root@slave3] out: drwxr-xr-x. 3 root root 22 10月 16 17:37 include
[root@slave3] out: drwxr-xr-x. 5 root root 51 11月 24 10:47 java
[root@slave3] out: drwxr-xr-x. 3 root root 24 10月 17 11:47 java_bak
[root@slave3] out: dr-xr-xr-x. 26 root root 4096 10月 16 17:38 lib
[root@slave3] out: dr-xr-xr-x. 40 root root 20480 10月 16 17:38 lib64
[root@slave3] out: drwxr-xr-x. 15 root root 4096 10月 28 16:41 libexec
[root@slave3] out: drwxr-xr-x. 12 root root 4096 10月 16 17:36 local
[root@slave3] out: dr-xr-xr-x. 2 root root 12288 10月 28 16:41 sbin
[root@slave3] out: drwxrwxr-x. 6 root root 46 10月 28 11:12 scala
[root@slave3] out: drwxr-xr-x. 71 root root 4096 10月 16 17:38 share
[root@slave3] out: drwxr-xr-x. 16 root root 4096 11月 10 17:59 spark
[root@slave3] out: drwxr-xr-x. 4 root root 32 10月 16 17:36 src
[root@slave3] out: drwxr-xr-x. 3 root root 19 1月 18 15:47 storm1.0.0
[root@slave3] out: drwxr-xr-x. 14 root root 4096 1月 18 13:57 storm1.1.1
[root@slave3] out: lrwxrwxrwx. 1 root root 10 10月 16 17:36 tmp -> ../var/tmp
[root@slave3] out: drwxr-xr-x. 14 root root 4096 1月 18 11:38 zookeeper
[root@slave3] out:
[root@slave3] run: df -kh
[root@slave3] out: 文件系统 容量 已用 可用 已用% 挂载点
[root@slave3] out: /dev/mapper/centos-root 36G 27G 9.2G 75% /
[root@slave3] out: devtmpfs 1.9G 0 1.9G 0% /dev
[root@slave3] out: tmpfs 1.9G 0 1.9G 0% /dev/shm
[root@slave3] out: tmpfs 1.9G 104M 1.8G 6% /run
[root@slave3] out: tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
[root@slave3] out: /dev/sda1 497M 125M 373M 25% /boot
[root@slave3] out: tmpfs 378M 0 378M 0% /run/user/0
[root@slave3] out:
Done.
Disconnecting from slave3... done.
Disconnecting from slave1... done.
Disconnecting from slave2... done.
[root@master ~]#