查看本地与远程主机信息

[root@node110 fabric]# cat simple1.py
#!/usr/bin/env python
from fabric.api import *


env.user='root'
env.hosts=['192.168.2.110','192.168.2.120']
env.password='123456'


@runs_once #只有第一台主机触发此函数(192.168.2.110)
def local_task():
    local("uname -a")


def remote_task():
    with cd("/tmp"):
        run("ls -l")


结果:
[root@node110 fabric]# fab -f simple1.py local_task
[192.168.2.110] Executing task 'local_task'
[localhost] local: uname -a
Linux node110 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


Done.
[root@node110 fabric]# fab -f simple1.py remote_task
[192.168.2.110] Executing task 'remote_task'
[192.168.2.110] run: ls -l
[192.168.2.110] out: total 56
[192.168.2.110] out: drwxrwxrwx 2 root root 4096 Apr  6 14:10 20170406-141048-b44f
[192.168.2.110] out: drwxrwxrwx 2 root root 4096 Apr  6 14:11 20170406-141138-9c69
[192.168.2.110] out: drwxrwxrwx 2 root root 4096 Apr  6 14:13 20170406-141345-597c
[192.168.2.110] out: -rw-r--r-- 1 root root  148 Apr  6 14:13 20170406-141345-597c.zip
[192.168.2.110] out: drwxrwxrwx 2 root root 4096 Apr  6 14:13 20170406-141357-b02c
[192.168.2.110] out: -rw-r--r-- 1 root root  148 Apr  6 14:13 20170406-141357-b02c.zip
[192.168.2.110] out: drwxrwxrwx 2 root root 4096 Apr  6 14:23 20170406-142330-5edb
[192.168.2.110] out: drwx------ 2 root root 4096 Apr  7 14:19 pip-no2_GG-unpack
[192.168.2.110] out: -rw------- 1 root root 1627 Apr  6 11:29 tmp34iWX9
[192.168.2.110] out: -rw------- 1 root root 1627 Apr  6 12:08 tmpENM7t2
[192.168.2.110] out: -rw------- 1 root root 1630 Apr  6 13:37 tmpEhKhtD
[192.168.2.110] out: -rw------- 1 root root 1627 Apr  6 12:10 tmpPzNYQw
[192.168.2.110] out: -rw------- 1 root root 1630 Apr  6 13:39 tmppxCQAs
[192.168.2.110] out: -rw------- 1 root root 1627 Apr  6 11:42 tmpxvsXEg
[192.168.2.110] out: 


[192.168.2.120] Executing task 'remote_task'
[192.168.2.120] run: ls -l
[192.168.2.120] out: total 344
[192.168.2.120] out: -rw-r--r-- 1 root root 350903 Apr 10 14:49 nginx_access.tar.gz
[192.168.2.120] out: -rw-r--r-- 1 root root      0 Feb 15 14:23 node110.txt
[192.168.2.120] out: -rw-r--r-- 1 root root      0 Feb 15 14:22 node120.txt
[192.168.2.120] out: -rw-r--r-- 1 root root      0 Feb 15 14:20 paramiko1.py
[192.168.2.120] out: -rw-r--r-- 1 root root      0 Feb 15 14:13 pramiko1.py
[192.168.2.120] out: 




Done.
Disconnecting from 192.168.2.110... done.
Disconnecting from 192.168.2.120... done.
分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS