1.copy 模块:把本地文件传输到指定路径;src 本地文件,dest目标文件。# 复制本地文件到指定路径[root@web1 ~]# ansible var -m copy -a "src=/ro
1.copy 模块:把本地文件传输到指定路径;src 本地文件,dest目标文件。
# 复制本地文件到指定路径[root@web1 ~]# ansible var -m copy -a "src=/root/test.log dest=/root/test.log.bak"
2.file 模块:文件操作(修改权限,新建目录等) state有如下参数 file,directory,link,hard,touch,absent
- state=touch 新建文件
- state=directory 新建目录
- state=absent 删除
# 权限操作,文件须存在,[root@web1 ~]# ansible var -m file -a "dest=/root/a.txt mode=600 owner=mysql group=mysql"# state=directory 新建目录;类似 mkdir -p[root@web1 ~]# ansible var -m file -a "dest=/root/txt mode=600 owner=mysql group=mysql state=directory"# state=absent 删除[root@web1 ~]# ansible var -m file -a "dest=/root/a.txt state=absent"
3.user 模块,state只有present,absent两个参数
# 新建用户[root@web1 ~]# ansible all -m user -a "name=foo password=<crypted password here>"# 删除用户[root@web1 ~]# ansible all -m user -a "name=foo state=absent"
4.yum 模块 state有如下参数 absent,present,installed,removed,latest
# 安装[root@web1 ~]# ansible webservers -m yum -a "name=name state=present"# yum install 指定版本[root@web1 ~]# ansible webservers -m yum -a "name=name1.5 state=present"# yum install 最新版本[root@web1 ~]# ansible webservers -m yum -a "name=name state=latest"# yum remove [root@web1 ~]# ansible webservers -m yum -a "name=name state=removed"
5.server 模块有如下参数 running,started,stopped,restarted,reloaded
# 启动[root@web1 ~]# ansible webservers -m service -a "name=httpd state=started"# 重启[root@web1 ~]# ansible webservers -m service -a "name=httpd state=restarted"# 重载[root@web1 ~]# ansible webservers -m service -a "name=httpd state=reloaded"# 停止[root@web1 ~]# ansible webservers -m service -a "name=httpd state=stopped"