1.comand模块 (默认模块)
用于在远程主机(被管理的主机)上执行某个命令
注:A. 不能变量$HOME和操作等"<",">","|",";“和”&"
#在默认家目录下创建一个 ansible.txt的文件
[root@cdhnode1 ~]# ansible all -m command -a " touch ansible.txt "
#指定切换到/home/zx目录下,再创建一个ansible.txt的文件
[root@cdhnode1 ~]# ansible all -a "chdir=/home/zx touch ansible.txt "
[root@cdhnode1 ~]# ansible all -m command -a " creates=/root/ansible.txt touch ansible2.txt "
# 当/home/zx/ansible.txt文件存,就执行删除操作
[root@cdhnode1 ~]# ansible all -m command -a " chdir=/home/zx removes=ansible.txt rm ansible.txt "
2.copy模块
把管理端的数据分发到被管理端服务器上
[root@cdhnode1 ~]# ansible all -m copy -a "src=/root/test.txt dest=/root/ "
[root@cdhnode1 ~]# ansible all -m copy -a "src=/root/test.txt dest=/root/ owner=ldg group=ldg backup=yes mode=600 "
##创建一个密码文件
[root@cdhnode1 ~]# ansible all -m copy -a " content=123456 dest=/root/mytest.password "
3.shell模块( 万能模块)
功能: 在被管理机中执行操作
注: 1.没有 command 模块的限制
2.参数列表与command 相拟
4.script 模块
需求,要在我管理的主机上批量创建用户
要在管理机上执行批量创建用户的脚本
以前要执行的方式:
a.创批量创建用户的脚本 ----addUsers.sh
b. 分发到各个机子上
c.设置执行权限 chmod a+x
d.执行要脚本
使用 ansible在管理机上编写好脚本,会自动分发并执行
注: 参数列表功能与command模块相拟
[root@cdhnode1 ~]# ansible all -m script -a "/root/test.sh "