1.command,shell,raw,script模块的作用和区别
command模块 [执行远程命令]
script模块 [在远程主机执行主控端的shell/python脚本]
shell模块 [执行远程主机的shell/python脚本]
raw模块 [类似于command模块、支持管道传递]
ansible基础配置
vim /etc/ansible/ansible.cfg
command 模块的使用: 去执行一个脚本文件command.sh, command.sh文件的功能是echo "I am command module"
shell模块执行命令 ls /root | grep txt
raw模块执行pwd命令
script模块执行 script.sh文件,文件的内容为 echo "I am script module"
2.file模块:
创建文件,并指定用户,用户组为student,且权限为600
[root@server ~]# ansible test70 -m file -a "path=.testdir/abc state=touch mode=0600
owner=student"
[root@server ~]# ansible test70 -m file -a "path=/testdir/abc owner=student"
[root@server ~]# ansible test70 -m file -a "path=/testdir/abc state=directory owner=student"
[root@server ~]# ansible test70 -m file -a "path=/testdir/abc group=student"
创建目录,并指定用户,用户组为student,且权限为755
[root@server ~]# ansible test70 -m file -a "path=/testdir/abd state=directory mode= 0755
owner=student group=student recurse=yes"
创建链接文件
[root@server ~]# ansible test70 -m file -a "path=/testdir/hardfile state=hard src=/testdir/testfile"
删除第一个创建的文件
[root@server ~]# ansible test70 -m file -a "path=/testdir/testdir state=absent"
3.copy
复制文件
复制目录
[root@server ~]# ansible test70 -m copy -a "src=/testdir/copytest dest=/opt/ force=no"
4.fetch
从被控制主机上取文件
5.synchronize
pull: 从被控制主机上拉取目录
[root@server ansible_dir]# ansible node1.example.com -m synchronzie -a 'src=/etc/hosts dest=/tmp mode=pull'
push:往被控制主机上推送目录
[root@server ansible_dir]# ansible node1.example.com -m synchronzie -a 'src=/etc/hosts dest=/tmp mode=push'