|
一 自动安装软件包
lansible testhost -m yum -a "name=httpd "
在name后面还可以加上state=installed ##安装httpd软件
ansible testhost -m yum -a "name=httpd state=removed" ##卸载http软件包
1
2
3
4
5
6
| 例子:ansible 192.168.253.131 -m yum -a "name=vim-enhanced"
^L192.168.253.131 | success >> {
"changed": true,
"msg": "",
"rc": 0,
"results": [(部分内容)##安装vim这个命令的软件包
|
二 管理服务
lansible testhost -m service -a "name=httpd state=started enabled=yes"
这里的name是centos系统里的服务名,可以通过chkconfig --list查到。
停止httpd服务
1
2
3
4
5
6
7
| 例子:[iyunv@web9 ~]# ansible 192.168.253.131 -m service -a "name=httpd state=stopped enabled=yes"
192.168.253.131 | success >> {
"changed": true,
"enabled": true,
"name": "httpd",
"state": "stopped"
}
|
最后去客户端查看
lAnsible文档的使用
lansible-doc -l 列出所有的模块
ansible-doc cron 查看指定模块的文档
|
|
|