一、常用模块
1.ping 模块
用于确认与对象机器是否能够ping通,正常情况返回pong。可以设置data
不是ICMP ping,只是一个简单的模块
对于windows目标,请改用win_ping模块
对于网络目标,请改用net_ping模块
1 # 默认返回是pong 2 [root@Ansible ~]# ansible web -m ping 3 192.168.8.66 | SUCCESS => { 4 "changed": false, 5 "ping": "pong" 6 } 7 8 # 设置返回值是hello 9 [root@Ansible ~]# ansible web -m ping -a "data=hello" 10 192.168.8.66 | SUCCESS => { 11 "changed": false, 12 "ping": "hello" 13 } 14 15 # 设置返回值是crash,模块导致异常 16 [root@Ansible ~]# ansible web -m ping -a "data=crash" 17 192.168.8.66 | FAILED! => { 18 "changed": false, 19 "module_stderr": "Shared connection to 192.168.8.66 closed.\r\n", 20 "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_oNemnu/ansible_module_ping.py\", line 84, in <module>\r\n main()\r\n File \"/tmp/ansible_oNemnu/ansible_module_ping.py\", line 74, in main\r\n raise Exception(\"boom\")\r\nException: boom\r\n", 21 "msg": "MODULE FAILURE", 22 "rc": 1 23 }
2.command 模块
command模块用于在远程主机上执行命令,ansible默认就是使用command模块。
command模块有一个缺陷就是不能使用管道符和重定向功能
1 [root@aliyun ~]# ansible all -a 'pwd' 2 yxd_2 | CHANGED | rc=0 >> 3 /app/yxd 4 mantis_2 | CHANGED | rc=0 >> 5 /app/mantis 6 mantis_1 | CHANGED | rc=0 >> 7 /app/mantis 8 yxd_1 | CHANGED | rc=0 >> 9 /app/yxd
对于Windows目标,请改用win_command模块
标签:ping,192.168,学习,ansible,command,模块,rc From: https://www.cnblogs.com/dxtx/p/16645208.html