1.command,shell,raw,script模块的作用和区别
1.1command shell raw区别
command、shell模块:
相同点:要求受管主机上安装Python。
不同点:command可以在受管主机上执行shell命令,但是不支持环境变量和操作符(例如 '|', '<', '>', '&')
shell模块调用的/bin/sh指令执行。
raw模块:
不需要受管主机上安装Python,直接使用远程shell运行命令,通常用于无法安装Python的系统(例如网络设备等)。
- command
- shell
- raw
应尽量避免使用这三个模块来执行命令,因为其他模块大部分都是幂等性的,可以自动进行更改跟踪。command、shell、raw不具备幂等性。注: 幂等性:简单来讲,就是输入相同,输出相同,无论多少次比如说,确认接口,如果传入订单号,返回确认OK,如果已经确认过了,再次调用确认接口,返回如果还是确认OK,那么这个接口就是满足幂等性.
2、command 模块的使用: 去执行一个脚本文件command.sh, command.sh文件的功能是echo "I am command module"
[root@server ~]#vim command.sh
[root@server ~]# more ./.ansible/inventory
node1
[node]
node1
[node1:children]
node
test
[test]
node2
[root@server ~]# ansible node -m copy -a "src=/root/command.sh dest=/home/student"
[WARNING]: Found both group and host with same