1.command,shell,raw,script模块的作用和区别
command 模块的使用: 去执行一个脚本文件command.sh, command.sh文件的功能是echo "I am command module"
首先创建一个脚本文件,然后往里添加内容
[root@server ~]# ansible node -m command -a "sh command.sh chdir=/root"
node1.example.com | CHANGED | rc=0 >>
I am command module?
[root@server ~]#
shell模块执行命令 ls /root | grep txt
[root@server ~]# ansible node -m shell -a "ls /root | grep txt"
node1.example.com | CHANGED | rc=0 >>
money.txt
[root@server ~]#
raw模块执行pwd命令
[root@server ~]# ansible node -m raw -a "pwd"
node1.example.com | CHANGED | rc=0 >>
/home/student
Shared connection to node1.example.com closed.
[root@server ~]#
script模块执行 script.sh文件,文件的内容为 echo "I am script module"
注意:和 shell 模块的不同,shell 模块是要求客户端上有这个脚本才能执行;script 是要求 ansible 服务端有这个脚本就可以了,执行的时候是不会拷贝这个脚本到客户端的
首先server和node1两台机器都得创建script.sh文件然后向其中输入内容
此时即可执行
2.file模块:
创建文件,并指定用户,用户组为student, 且权限为600
创建目录,并指定用户,用户组为student, 且权限为755
创建链接文件
删除第一个创建的文件
3.copy
复制文件
复制目录
4.fetch
从被控制主机上取文件
[root@server ~]# ansible node -m fetch -a "src=/root/file4 dest=/root/"
node1.example.com | CHANGED => {
"changed": true,
"checksum": "17c0bec21ea7fe918e2b81bc76a2597cbc56a7fd",
"dest": "/root/node1.example.com/root/file4",
"md5sum": "64f465081aeff198562ba2f37d721e79",
"remote_checksum": "17c0bec21ea7fe918e2b81bc76a2597cbc56a7fd",
"remote_md5sum": null
}
[root@server ~]#
5.synchronize
pull: 从被控制主机上拉取目录
push:往被控制主机上推送目录