标签:ansible常用模块
ansible 默认提供了很多模块来供我们使用。在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansible 都支持哪些模块,通过 ansible-doc -s 模块名 又可以查看该模块有哪些参数可以使用。
下面介绍比较常用的几个模块:
copy模块 file模块 cron模块 group模块 user模块 yum模块 service模块 script模块 ping模块 command模块 raw模块 get_url模块 synchronize模块
copy模块:
目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上
命令:ansible web -m copy -a ‘src=/root/a.sh dest=/tmp‘
执行效果:
[root@ansiable ~]# ansible web -m copy -a ‘src=/root/a.sh dest=/tmp‘
192.168.3.46 | success >> {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/tmp/a.sh",
"gid": 0,
"group": "root",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"mode": "0644",
"owner": "root",
"size": 0,
"src": "/root/.ansible/tmp/ansible-tmp-1435822744.89-119716035059263/source",
"state": "file",
"uid": 0
}
192.168.3.45 | success >> {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/tmp/a.sh",
"gid": 0,
"group": "root",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"mode": "0644",
"owner": "root",
"size": 0,
"src": "/root/.ansible/tmp/ansible-tmp-1435822744.9-32249610150959/source",
"state": "file",
"uid": 0
}
#在目标机器上查看结果
[root@ansiable ~]# ansible web -m shell -a ‘ls /tmp |grep a.sh‘
192.168.3.45 | success | rc=0 >>
a.sh
192.168.3.46 | success | rc=0 >>
a.shfile模块:
目的:更改指定节点上/tmp/a.sh的权限为755,属主和属组为root
命令:ansible web -m file -a ‘dest=/tmp/a.sh mode=755 owner=root group=root‘
执行效果:
#首先查看目标机器上的文件权限
[root@ansiable ~]# ansible web -m shell -a ‘ls -l /tmp |grep a.sh‘
192.168.3.46 | success | rc=0 >>
-rw-r--r-- 1 root root 0 Jul 2 15:39 a.sh
192.168.3.45 | success | rc=0 >>
-rw-r--r-- 1 root root 0 Jul 2 15:10 a.sh
#修改权限
[root@ansiable ~]# ansible web -m file -a ‘dest=/tmp/a.sh mode=755 owner=root group=root‘
192.168.3.46 | success >> {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/tmp/a.sh",
"size": 0,
"state": "file",
"uid": 0
}
192.168.3.45 | success >> {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/tmp/a.sh",
"size": 0,
"state": "file",
"uid": 0
}
#再次查看文件权限
[root@ansiable ~]# ansible web -m shell -a ‘ls -l /tmp |grep a.sh‘
192.168.3.45 | success | rc=0 >>
-rwxr-xr-x 1 root root 0 Jul 2 15:10 a.sh #权限从644变成755了
192.168.3.46 | success | rc=0 >>
-rwxr-xr-x 1 root root 0 Jul 2 15:39 a.shcron模块:
目的:在指定节点上定义一个计划任务,每隔3分钟到主控端更新一次时间
命令:ansible web -m cron -a ‘name="ntpdate" minute=*/30 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null"‘
执行效果:
#添加crontab任务
[root@ansiable ~]# ansible web -m cron -a ‘name="ntpdate" minute=*/30 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null"‘
192.168.3.45 | success >> {
"changed": true,
"jobs": [
"ntpdate"
]
}
192.168.3.46 | success >> {
"changed": true,
"jobs": [
"ntpdate"
]
}
#查看结果
[root@ansiable ~]# ansible web -m shell -a ‘crontab -l‘
192.168.3.46 | success | rc=0 >>
#Ansible: ntpdate
*/30 * * * * /usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null
192.168.3.45 | success | rc=0 >>
#Ansible: ntpdate
*/30 * * * * /usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null
#删除crontab任务,增加参数state=absent
[root@ansiable ~]# ansible web -m cron -a ‘name="ntpdate" state=absent minute=*/30 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null"‘
192.168.3.45 | success >> {
"changed": true,
"jobs": []
}
192.168.3.46 | success >> {
"changed": true,
"jobs": []
}
#再次查看结果
[root@ansiable ~]# ansible web -m shell -a ‘crontab -l‘
192.168.3.46 | success | rc=0 >>
192.168.3.45 | success | rc=0 >>group模块:
目的:在所有节点上创建一个组名为nolinux,gid为2015的组
命令:ansible web -m group -a ‘gid=2015 name=nolinux‘
执行效果:
#添加组
[root@ansiable ~]# ansible web -m group -a ‘gid=2015 name=nolinux‘
192.168.3.46 | success >> {
"changed": true,
"gid": 2015,
"name": "nolinux",
"state": "present",
"system": false
}
192.168.3.45 | success >> {
"changed": true,
"gid": 2015,
"name": "nolinux",
"state": "present",
"system": false
}
#查看结果
[root@ansiable ~]# ansible web -m shell -a ‘grep nolinux /etc/group‘
192.168.3.46 | success | rc=0 >>
nolinux:x:2015:
192.168.3.45 | success | rc=0 >>
nolinux:x:2015:user模块:
目的:在指定节点上创建一个用户名为nolinux,组为nolinux的用户
命令:ansible web -m user -a ‘name=nolinux groups=nolinux state=present‘
执行命令:
[root@ansiable ~]# ansible web -m user -a ‘name=nolinux groups=nolinux state=present‘
192.168.3.46 | success >> {
"changed": true,
"comment": "",
"createhome": true,
"group": 100,
"groups": "nolinux",
"home": "/home/nolinux",
"name": "nolinux",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
192.168.3.45 | success >> {
"changed": true,
"comment": "",
"createhome": true,
"group": 100,
"groups": "nolinux",
"home": "/home/nolinux",
"name": "nolinux",
"shell": "/bin/bash",
"state": "present",
"system": false,
"uid": 1001
}
[root@ansiable ~]# ansible web -m shell -a ‘grep nolinux /etc/passwd‘
192.168.3.46 | success | rc=0 >>
nolinux:x:1001:100::/home/nolinux:/bin/bash
192.168.3.45 | success | rc=0 >>
nolinux:x:1001:100::/home/nolinux:/bin/bashyum模块:
目的:在指定节点上安装 lrzsz 服务
命令:ansible web -m yum -a ‘state=present name=httpd‘
执行效果:
#通过yum块安装httpd
[root@ansiable ~]# ansible web -m yum -a ‘state=present name=httpd‘
192.168.3.45 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror, security\nLoading mirror speeds from cached hostfile\n * base: mirrors.pubyun.com\n * extras: mirrors.pubyun.com\n * updates: mirrors.pubyun.com\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed\n--> Processing Dependency: httpd-tools = 2.2.15-39.el6.centos for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed\n---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package httpd-tools.x86_64 0:2.2.15-39.el6.centos will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.2.15-39.el6.centos base 825 k\nInstalling for dependencies:\n apr x86_64 1.3.9-5.el6_2 base 123 k\n apr-util x86_64 1.3.9-3.el6_0.1 base 87 k\n apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k\n httpd-tools x86_64 2.2.15-39.el6.centos base 75 k\n\nTransaction Summary\n================================================================================\nInstall 5 Package(s)\n\nTotal download size: 1.1 M\nInstalled size: 3.6 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal 1.7 MB/s | 1.1 MB 00:00 \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Installing : apr-1.3.9-5.el6_2.x86_64 1/5 \n\r Installing : apr-util-1.3.9-3.el6_0.1.x86_64 2/5 \n\r Installing : httpd-tools-2.2.15-39.el6.centos.x86_64 3/5 \n\r Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 4/5 \n\r Installing : httpd-2.2.15-39.el6.centos.x86_64 5/5 \n\r Verifying : httpd-2.2.15-39.el6.centos.x86_64 1/5 \n\r Verifying : httpd-tools-2.2.15-39.el6.centos.x86_64 2/5 \n\r Verifying : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 3/5 \n\r Verifying : apr-util-1.3.9-3.el6_0.1.x86_64 4/5 \n\r Verifying : apr-1.3.9-5.el6_2.x86_64 5/5 \n\nInstalled:\n httpd.x86_64 0:2.2.15-39.el6.centos \n\nDependency Installed:\n apr.x86_64 0:1.3.9-5.el6_2 \n apr-util.x86_64 0:1.3.9-3.el6_0.1 \n apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 \n httpd-tools.x86_64 0:2.2.15-39.el6.centos \n\nComplete!\n"
]
}
192.168.3.46 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"Loaded plugins: fastestmirror, security\nLoading mirror speeds from cached hostfile\n * base: mirrors.pubyun.com\n * extras: mirrors.pubyun.com\n * updates: mirrors.pubyun.com\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-39.el6.centos will be installed\n--> Processing Dependency: httpd-tools = 2.2.15-39.el6.centos for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-39.el6.centos.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed\n---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package httpd-tools.x86_64 0:2.2.15-39.el6.centos will be installed\n--> Processing Dependency: libssl.so.10(libssl.so.10)(64bit) for package: httpd-tools-2.2.15-39.el6.centos.x86_64\n--> Processing Dependency: libcrypto.so.10(libcrypto.so.10)(64bit) for package: httpd-tools-2.2.15-39.el6.centos.x86_64\n---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed\n--> Running transaction check\n---> Package openssl.x86_64 0:1.0.0-27.el6 will be updated\n---> Package openssl.x86_64 0:1.0.1e-30.el6.11 will be an update\n--> Processing Dependency: make for package: openssl-1.0.1e-30.el6.11.x86_64\n--> Running transaction check\n---> Package make.x86_64 1:3.81-20.el6 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.2.15-39.el6.centos base 825 k\nInstalling for dependencies:\n apr x86_64 1.3.9-5.el6_2 base 123 k\n apr-util x86_64 1.3.9-3.el6_0.1 base 87 k\n apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k\n httpd-tools x86_64 2.2.15-39.el6.centos base 75 k\n mailcap noarch 2.1.31-2.el6 base 27 k\n make x86_64 1:3.81-20.el6 base 389 k\nUpdating for dependencies:\n openssl x86_64 1.0.1e-30.el6.11 updates 1.5 M\n\nTransaction Summary\n================================================================================\nInstall 7 Package(s)\nUpgrade 1 Package(s)\n\nTotal download size: 3.0 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal 1.9 MB/s | 3.0 MB 00:01 \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Installing : apr-1.3.9-5.el6_2.x86_64 1/9 \n\r Installing : apr-util-1.3.9-3.el6_0.1.x86_64 2/9 \n\r Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 3/9 \n\r Installing : mailcap-2.1.31-2.el6.noarch 4/9 \n\r Installing : 1:make-3.81-20.el6.x86_64 5/9 \n\r Updating : openssl-1.0.1e-30.el6.11.x86_64 6/9 \n\r Installing : httpd-tools-2.2.15-39.el6.centos.x86_64 7/9 \n\r Installing : httpd-2.2.15-39.el6.centos.x86_64 8/9 \n\r Cleanup : openssl-1.0.0-27.el6.x86_64 9/9 \n\r Verifying : httpd-2.2.15-39.el6.centos.x86_64 1/9 \n\r Verifying : openssl-1.0.1e-30.el6.11.x86_64 2/9 \n\r Verifying : httpd-tools-2.2.15-39.el6.centos.x86_64 3/9 \n\r Verifying : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 4/9 \n\r Verifying : apr-1.3.9-5.el6_2.x86_64 5/9 \n\r Verifying : 1:make-3.81-20.el6.x86_64 6/9 \n\r Verifying : mailcap-2.1.31-2.el6.noarch 7/9 \n\r Verifying : apr-util-1.3.9-3.el6_0.1.x86_64 8/9 \n\r Verifying : openssl-1.0.0-27.el6.x86_64 9/9 \n\nInstalled:\n httpd.x86_64 0:2.2.15-39.el6.centos \n\nDependency Installed:\n apr.x86_64 0:1.3.9-5.el6_2 \n apr-util.x86_64 0:1.3.9-3.el6_0.1 \n apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 \n httpd-tools.x86_64 0:2.2.15-39.el6.centos \n mailcap.noarch 0:2.1.31-2.el6 \n make.x86_64 1:3.81-20.el6 \n\nDependency Updated:\n openssl.x86_64 0:1.0.1e-30.el6.11 \n\nComplete!\n"
]
}
#确认结果
[root@ansiable ~]# ansible web -m shell -a ‘rpm -qa |grep httpd‘
192.168.3.46 | success | rc=0 >>
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64
192.168.3.45 | success | rc=0 >>
httpd-2.2.15-39.el6.centos.x86_64
httpd-tools-2.2.15-39.el6.centos.x86_64service模块:
目的:启动指定节点上的 httpd 服务,并让其开机自启动
命令:ansible web -m service -a ‘name=httpd state=started enabled=yes‘
执行效果:
#启动服务
[root@ansiable ~]# ansible web -m service -a ‘name=httpd state=started enabled=yes‘
192.168.3.45 | success >> {
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started"
}
192.168.3.46 | success >> {
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started"
}
#查看结果
[root@ansiable ~]# ansible web -m shell -a ‘netstat -tunlp |grep httpd‘
192.168.3.45 | success | rc=0 >>
tcp 0 0 :::80 :::* LISTEN 3899/httpd
192.168.3.46 | success | rc=0 >>
tcp 0 0 :::80 :::* LISTEN 2547/httpd
[root@ansiable ~]# ansible web -m shell -a ‘chkconfig |grep httpd‘
192.168.3.45 | success | rc=0 >>
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
192.168.3.46 | success | rc=0 >>
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:offscript模块:
目的:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)
命令:ansible web -m script -a ‘/root/a.sh‘
执行效果:
#查看节点脚本内容
[root@ansiable ~]# ansible web -m shell -a ‘cat /root/a.sh‘
192.168.3.45 | success | rc=0 >>
#!/bin/bash
date
192.168.3.46 | success | rc=0 >>
#!/bin/bash
date
#执行脚本
[root@ansiable ~]# ansible web -m script -a ‘/root/a.sh‘
192.168.3.45 | success >> {
"changed": true,
"rc": 0,
"stderr": "",
"stdout": ""
}
192.168.3.46 | success >> {
"changed": true,
"rc": 0,
"stderr": "",
"stdout": ""
}ping模块:
目的:检查指定节点机器是否还能连通
命令:ansible web -m ping
执行效果:
[root@ansiable ~]# ansible web -m ping
192.168.3.46 | success >> {
"changed": false,
"ping": "pong"
}
192.168.3.45 | success >> {
"changed": false,
"ping": "pong"
}command模块:
目的:在指定节点上运行hostname命令
命令:ansible web -m command -a ‘hostname‘
执行效果:
[root@ansiable ~]# ansible web -m command -a ‘hostname‘ 192.168.3.45 | success | rc=0 >> kvm 192.168.3.46 | success | rc=0 >> initator
raw模块:
目的:在节点上运行hostname命令
命令:ansible web -m raw -a ‘ls -l /root |grep -v total‘
执行效果:
[root@ansiable ~]# ansible web -m raw -a ‘ls -l /root |grep -v total‘ 192.168.3.45 | success | rc=0 >> -rw-------. 1 root root 2790 Jul 1 10:09 anaconda-ks.cfg -rwxr-xr-x 1 root root 19 Jul 2 16:21 a.sh -rw-r--r--. 1 root root 3305 Jul 1 10:09 cobbler.ks -rw-r--r--. 1 root root 20504 Jul 1 10:09 install.log -rw-r--r--. 1 root root 5882 Jul 1 10:08 install.log.syslog -rw-r--r--. 1 root root 2241 Jul 1 10:09 ks-post.log -rw-r--r--. 1 root root 1 Jul 1 10:09 ks-post-nochroot.log -rw-r--r--. 1 root root 1025 Jul 1 10:06 ks-pre.log 192.168.3.46 | success | rc=0 >> -rw-------. 1 root root 2790 Jul 1 14:03 anaconda-ks.cfg -rwxr-xr-x 1 root root 17 Jul 2 16:48 a.sh -rw-r--r--. 1 root root 3305 Jul 1 14:03 cobbler.ks -rw-r--r--. 1 root root 20504 Jul 1 14:03 install.log -rw-r--r--. 1 root root 5882 Jul 1 14:02 install.log.syslog -rw-r--r--. 1 root root 2241 Jul 1 14:03 ks-post.log -rw-r--r--. 1 root root 1 Jul 1 14:03 ks-post-nochroot.log -rw-r--r--. 1 root root 978 Jul 1 14:00 ks-pre.log
get_url模块:
目的:将http://www.baidu.com文件下载到指定节点的/tmp目录下
命令:ansible web -m get_url -a ‘url=http://www.baidu.com dest=/tmp‘
执行效果:
[root@ansiable ~]# ansible web -m get_url -a ‘url=http://www.baidu.com dest=/tmp‘
192.168.3.45 | success >> {
"changed": true,
"checksum": "2e2d144ee9771f6800e0c1d066d37ddb0f610007",
"dest": "/tmp/index.html",
"gid": 0,
"group": "root",
"md5sum": "bf8c3f60eb511ff162bfa0fb104f4593",
"mode": "0644",
"msg": "OK (unknown bytes)",
"owner": "root",
"sha256sum": "",
"size": 94380,
"src": "/tmp/tmpLw1x3P",
"state": "file",
"uid": 0,
"url": "http://www.baidu.com"
}
192.168.3.46 | success >> {
"changed": true,
"checksum": "c00523365ac143a059d252c2cef1a3dfc0f50c7c",
"dest": "/tmp/index.html",
"gid": 0,
"group": "root",
"md5sum": "32a45428f13b7208b30468632810dad7",
"mode": "0644",
"msg": "OK (unknown bytes)",
"owner": "root",
"sha256sum": "",
"size": 93384,
"src": "/tmp/tmp6308VW",
"state": "file",
"uid": 0,
"url": "http://www.baidu.com"
}
#查看结果
[root@ansiable ~]# ansible web -m shell -a ‘ls -l /tmp‘
192.168.3.46 | success | rc=0 >>
total 100
-rwxr-xr-x 1 root root 0 Jul 2 15:39 a.sh
-rw-r--r-- 1 root root 93384 Jul 2 17:04 index.html
-rwx------. 1 root root 1236 Jul 1 14:03 ks-script-8q9d7h
-rwxr-xr-x. 1 root root 37 Jul 1 14:03 ks-script-8q9d7h.log
-rw-------. 1 root root 0 Jul 1 14:00 yum.log
192.168.3.45 | success | rc=0 >>
total 104
-rwxr-xr-x 1 root root 0 Jul 2 15:10 a.sh
-rw-r--r-- 1 root root 94380 Jul 2 17:04 index.html #刚下载的文件
-rwx------. 1 root root 1236 Jul 1 10:09 ks-script-7sY7Px
-rwxr-xr-x. 1 root root 37 Jul 1 10:09 ks-script-7sY7Px.log
-rw-------. 1 root root 0 Jul 1 10:06 yum.logsynchronize模块:
目的:将主控方/root/目录推送到指定节点的/tmp目录下
命令:ansible web -m synchronize -a ‘src=/root/ dest=/tmp delete=yes compress=yes ‘
执行效果:
delete=yes 使两边的内容一样(即以推送方为主)
compress=yes 开启压缩,默认为开启
--exclude=.git 忽略同步.git结尾的文件
[root@ansiable ~]# ll /root/ total 56 -rw-------. 1 root root 2795 Jun 23 16:52 anaconda-ks.cfg -rw-r--r-- 1 root root 0 Jul 2 15:38 a.sh -rw-r--r--. 1 root root 3305 Jun 23 16:52 cobbler.ks -rw-r--r--. 1 root root 20504 Jun 23 16:52 install.log -rw-r--r--. 1 root root 5882 Jun 23 16:51 install.log.syslog -rw-r--r--. 1 root root 2241 Jun 23 16:52 ks-post.log -rw-r--r--. 1 root root 1 Jun 23 16:52 ks-post-nochroot.log -rw-r--r--. 1 root root 978 Jun 23 16:48 ks-pre.log [root@ansiable ~]# ansible web -m synchronize -a ‘src=/root/ dest=/tmp delete=yes compress=yes ‘ #查看结果 [root@ansiable ~]# ansible web -m shell -a ‘ls -l /tmp/‘ 192.168.3.46 | success | rc=0 >> total 52 -rw-r--r-- 1 root root 0 Jul 2 15:38 a.sh -rw------- 1 root root 2795 Jun 23 16:52 anaconda-ks.cfg -rw-r--r-- 1 root root 3305 Jun 23 16:52 cobbler.ks -rw-r--r-- 1 root root 20504 Jun 23 16:52 install.log -rw-r--r-- 1 root root 5882 Jun 23 16:51 install.log.syslog -rw-r--r-- 1 root root 1 Jun 23 16:52 ks-post-nochroot.log -rw-r--r-- 1 root root 2241 Jun 23 16:52 ks-post.log -rw-r--r-- 1 root root 978 Jun 23 16:48 ks-pre.log 192.168.3.45 | success | rc=0 >> total 52 -rw-r--r-- 1 root root 0 Jul 2 15:38 a.sh -rw------- 1 root root 2795 Jun 23 16:52 anaconda-ks.cfg -rw-r--r-- 1 root root 3305 Jun 23 16:52 cobbler.ks -rw-r--r-- 1 root root 20504 Jun 23 16:52 install.log -rw-r--r-- 1 root root 5882 Jun 23 16:51 install.log.syslog -rw-r--r-- 1 root root 1 Jun 23 16:52 ks-post-nochroot.log -rw-r--r-- 1 root root 2241 Jun 23 16:52 ks-post.log -rw-r--r-- 1 root root 978 Jun 23 16:48 ks-pre.log
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1670231
标签:ansible常用模块
原文地址:http://ly36843.blog.51cto.com/3120113/1670231