23fwerw 发表于 2016-4-22 10:07:11

ansible安装rpm包/管理服务

ansible web10.gz.com -m yum-a "name=httpd"
在name后面还可以加上state=installed
用yum安装一个httpd


1
2
3
4
5
6
7
8
9
# 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\rVerifying: httpd-2.2.                  15-47.el6.centos.4.x86_64                        1/3 \n\rVerifying: httpd-tools-2.2.15-47.el6.centos.4.x86_64                                    2/3 \n\rVerifying: apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         3/3 \n\n已安装:\nhttpd.x86_64 0:2                  .2.15-47.el6.centos.4                                       \n\n作为依赖被安装:\napr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                                          \nhttpd-tools.x86_64 0:2.2.15-47.el6.centos.4                                 \n\n完毕                  !\n"
    ]
}




查看有没有安装


1
2
# ps aux |grep httpd
root      46650.00.0 103316   896 pts/0    S+   03:35   0:00 grep httpd




比如安装vim


1
2
3
4
5
6
7
8
9
# 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
# 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
# ps aux |grep httpd
root      47660.00.3 1752763748 ?      Ss   03:40   0:00 /usr/sbin/httpd
apache    47680.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47690.00.2 1752762460 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47700.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47710.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47720.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47730.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47740.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
apache    47750.00.2 1752762444 ?      S    03:40   0:00 /usr/sbin/httpd
root      47780.00.0 103316   892 pts/0    S+   03:43   0:00 grep httpd
# chkconfig --list httpd
httpd         0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭





ansible文档的使用
列出所有的模块 按q退出


1
# ansible-doc -l





查看指定模块的文档

1
# ansible-doc cron






页: [1]
查看完整版本: ansible安装rpm包/管理服务