|
ansible web10.gz.com -m yum-a "name=httpd"
在name后面还可以加上state=installed
用yum安装一个httpd
1
2
3
4
5
6
7
8
9
| [iyunv@web9 ~]# ansible web10.gz.com -m yum -a "name=httpd"
web10.gz.com | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"已加载插件:fastestmirror\n设置安装进程\nLoading mirror speeds from cached hostfile\n * base: mirrors.zju.edu.cn\n * e pel: mirrors.neusoft.edu.cn\n * extras: mirrors.neusoft.edu.cn\n * updates: mirrors.zju.edu.cn\n解决依赖关系\n--> 执行事务检查\ n---> Package httpd.x86_64 0:2.2.15-47.el6.centos.4 will be 安装\n--> 处理依赖关系 httpd-tools = 2.2.15-47.el6.centos.4,它被软 件包 httpd-2.2.15-47.el6.centos.4.x86_64 需要\n--> 处理依赖关系 apr-util-ldap,它被软件包 httpd-2.2.15-47.el6.centos.4.x86_64 需要\n--> 执行事务检查\n---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be 安装\n---> Package httpd-tools.x86_64 0:2.2 .15-47.el6.centos.4 will be 安装\n--> 完成依赖关系计算\n\n依赖关系解决\n\n===================================================== ===========================\n 软件包 架构 版本 仓库 大小\n================= ===============================================================\n正在安装:\n httpd x86_64 2.2.15-47.el6.cento s.4 updates 831 k\n为依赖而安装:\n apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k\n httpd-tools x86_64 2.2.15-47.el6.centos.4 updates 77 k\n\n事务概要\n=================================== =============================================\nInstall 3 Package(s)\n\n总下载量:924 k\nInstalled size: 3.1 M\n下载软件包 :\n--------------------------------------------------------------------------------\n总计 365 kB/s | 924 kB 00:02 \n运行 rpm_check_debug \n执行事务测试\n事务测试成功\n执行事务\n\r 正在安装 : apr-util -ldap-1.3.9-3.el6_0.1.x86_64 1/3 \n\r 正在安装 : httpd-tools-2.2.15-47.el6.centos.4.x86_64 2/3 \n\r 正在安装 : httpd-2.2.15-47.el6.centos.4.x86_64 3/3 \n\r Verifying : httpd-2.2. 15-47.el6.centos.4.x86_64 1/3 \n\r Verifying : httpd-tools-2.2.15-47.el6.centos.4.x86_64 2/3 \n\r Verifying : apr-util-ldap-1.3.9-3.el6_0.1.x86_64 3/3 \n\n已安装:\n httpd.x86_64 0:2 .2.15-47.el6.centos.4 \n\n作为依赖被安装:\n apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 \n httpd-tools.x86_64 0:2.2.15-47.el6.centos.4 \n\n完毕 !\n"
]
}
|
查看有没有安装
1
2
| [iyunv@web10 ~]# ps aux |grep httpd
root 4665 0.0 0.0 103316 896 pts/0 S+ 03:35 0:00 grep httpd
|
比如安装vim
1
2
3
4
5
6
7
8
9
| [iyunv@web9 ~]# ansible web10.gz.com -m yum -a "name=vim-enhanced"
web10.gz.com | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"vim-enhanced-2:7.4.629-5.el6.x86_64 providing vim-enhanced is already installed"
]
}
|
已经转过了的提示
怎么管理一个服务(这里的name是centos系统里的服务名,可通过chkconfig --list 查到)让他起来和开机启动
1
2
3
4
5
6
7
| [iyunv@web9 ~]# ansible web10.gz.com -m service -a "name=httpd state=started enabled=on"
web10.gz.com | SUCCESS => {
"changed": true,
"enabled": true,
"name": "httpd",
"state": "started"
}
|
查看有没有启动
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@web10 ~]# ps aux |grep httpd
root 4766 0.0 0.3 175276 3748 ? Ss 03:40 0:00 /usr/sbin/httpd
apache 4768 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4769 0.0 0.2 175276 2460 ? S 03:40 0:00 /usr/sbin/httpd
apache 4770 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4771 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4772 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4773 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4774 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
apache 4775 0.0 0.2 175276 2444 ? S 03:40 0:00 /usr/sbin/httpd
root 4778 0.0 0.0 103316 892 pts/0 S+ 03:43 0:00 grep httpd
[iyunv@web10 ~]# chkconfig --list httpd
httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
|
ansible文档的使用
列出所有的模块 按q退出
1
| [iyunv@web9 ~]# ansible-doc -l
|
查看指定模块的文档
1
| [iyunv@web9 ~]# ansible-doc cron
|
|
|
|