实例学习ansible系列(9)常用模块之yum/service
2016-07-31 05:44
901 查看
知识点:yum模块用于yum安装包安装和卸载等操作。
知识点:service模块用于系统服务管理操作,比如启动停止等操作。
安装
[root@host31 ~]# ansible host31 -m yum -a “name=httpd”
host31 | SUCCESS => {
“changed”: true,
“msg”: “”,
“rc”: 0,
“results”: [
“Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.yun-idc.com\n * epel: mirrors.ustc.edu.cn\n * extras: mirrors.btte.net\n * updates: mirrors.btte.net\nResolving Dependencies\n–> Running transaction check\n—> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed\n–> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Running transaction check\n—> Package apr.x86_64 0:1.4.8-3.el7 will be installed\n—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed\n—> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 will be installed\n—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed\n–> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.4.6-40.el7.centos.4 updates 2.7 M\nInstalling for dependencies:\n apr x86_64 1.4.8-3.el7 base 103 k\n apr-util x86_64 1.5.2-6.el7 base 92 k\n httpd-tools x86_64 2.4.6-40.el7.centos.4 updates 83 k\n mailcap noarch 2.1.41-2.el7 base 31 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package (+4 Dependent packages)\n\nTotal download size: 3.0 M\nInstalled size: 10 M\nDownloading packages:\n——————————————————————————–\nTotal 343 kB/s | 3.0 MB 00:08 \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : apr-1.4.8-3.el7.x86_64 1/5 \n Installing : apr-util-1.5.2-6.el7.x86_64 2/5 \n Installing : httpd-tools-2.4.6-40.el7.centos.4.x86_64 3/5 \n Installing : mailcap-2.1.41-2.el7.noarch 4/5 \n Installing : httpd-2.4.6-40.el7.centos.4.x86_64 5/5 \n Verifying : httpd-tools-2.4.6-40.el7.centos.4.x86_64 1/5 \n Verifying : apr-1.4.8-3.el7.x86_64 2/5 \n Verifying : mailcap-2.1.41-2.el7.noarch 3/5 \n Verifying : httpd-2.4.6-40.el7.centos.4.x86_64 4/5 \n Verifying : apr-util-1.5.2-6.el7.x86_64 5/5 \n\nInstalled:\n httpd.x86_64 0:2.4.6-40.el7.centos.4 \n\nDependency Installed:\n apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 \n httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7 \n\nComplete!\n”
]
}
[root@host31 ~]#
使用service模块启动httpd
确认启动状态
确认启动httpd
知识点:service模块用于系统服务管理操作,比如启动停止等操作。
使用yum模块安装httpd
事前确认未曾安装[root@host31 ~]# ansible host31 -m shell -a "rpm -qa |grep httpd" host31 | FAILED | rc=1 >> [root@host31 ~]#
安装
[root@host31 ~]# ansible host31 -m yum -a “name=httpd”
host31 | SUCCESS => {
“changed”: true,
“msg”: “”,
“rc”: 0,
“results”: [
“Loaded plugins: fastestmirror, langpacks\nLoading mirror speeds from cached hostfile\n * base: mirrors.yun-idc.com\n * epel: mirrors.ustc.edu.cn\n * extras: mirrors.btte.net\n * updates: mirrors.btte.net\nResolving Dependencies\n–> Running transaction check\n—> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed\n–> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64\n–> Running transaction check\n—> Package apr.x86_64 0:1.4.8-3.el7 will be installed\n—> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed\n—> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 will be installed\n—> Package mailcap.noarch 0:2.1.41-2.el7 will be installed\n–> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n httpd x86_64 2.4.6-40.el7.centos.4 updates 2.7 M\nInstalling for dependencies:\n apr x86_64 1.4.8-3.el7 base 103 k\n apr-util x86_64 1.5.2-6.el7 base 92 k\n httpd-tools x86_64 2.4.6-40.el7.centos.4 updates 83 k\n mailcap noarch 2.1.41-2.el7 base 31 k\n\nTransaction Summary\n================================================================================\nInstall 1 Package (+4 Dependent packages)\n\nTotal download size: 3.0 M\nInstalled size: 10 M\nDownloading packages:\n——————————————————————————–\nTotal 343 kB/s | 3.0 MB 00:08 \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Installing : apr-1.4.8-3.el7.x86_64 1/5 \n Installing : apr-util-1.5.2-6.el7.x86_64 2/5 \n Installing : httpd-tools-2.4.6-40.el7.centos.4.x86_64 3/5 \n Installing : mailcap-2.1.41-2.el7.noarch 4/5 \n Installing : httpd-2.4.6-40.el7.centos.4.x86_64 5/5 \n Verifying : httpd-tools-2.4.6-40.el7.centos.4.x86_64 1/5 \n Verifying : apr-1.4.8-3.el7.x86_64 2/5 \n Verifying : mailcap-2.1.41-2.el7.noarch 3/5 \n Verifying : httpd-2.4.6-40.el7.centos.4.x86_64 4/5 \n Verifying : apr-util-1.5.2-6.el7.x86_64 5/5 \n\nInstalled:\n httpd.x86_64 0:2.4.6-40.el7.centos.4 \n\nDependency Installed:\n apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 \n httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7 \n\nComplete!\n”
]
}
[root@host31 ~]#
>确认安装 [root@host31 ~]#ansible host31 -m shell -a "rpm -qa |grep httpd" host31 | SUCCESS | rc=0 >> httpd-tools-2.4.6-40.el7.centos.4.x86_64 httpd-2.4.6-40.el7.centos.4.x86_64 [root@host31 ~]#
使用service启动httpd服务
事前未曾启动[root@host31 ~]# ansible host31 -m shell -a "systemctl status httpd" host31 | FAILED | rc=3 >> ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd(8) man:apachectl(8) Jul 30 17:24:04 host31 systemd[1]: Starting The Apache HTTP Server... Jul 30 17:24:04 host31 httpd[63250]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.32.31. Set the 'ServerName' directive globally to suppress this message Jul 30 17:24:04 host31 systemd[1]: Started The Apache HTTP Server. Jul 30 17:25:15 host31 systemd[1]: Stopping The Apache HTTP Server... Jul 30 17:25:16 host31 systemd[1]: Stopped The Apache HTTP Server. [root@host31 ~]#
使用service模块启动httpd
[root@host31 ~]# ansible host31 -m service -a "name=httpd state=started" host31 | SUCCESS => { "changed": true, "name": "httpd", "state": "started" } [root@host31 ~]#
确认启动状态
[root@host31 ~]# ansible host31 -m shell -a "systemctl status httpd" host31 | SUCCESS | rc=0 >> ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2016-07-30 17:27:53 EDT; 1min 32s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 64517 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service tq64517 /usr/sbin/httpd -DFOREGROUND tq64521 /usr/sbin/httpd -DFOREGROUND tq64522 /usr/sbin/httpd -DFOREGROUND tq64523 /usr/sbin/httpd -DFOREGROUND tq64524 /usr/sbin/httpd -DFOREGROUND mq64528 /usr/sbin/httpd -DFOREGROUND Jul 30 17:27:53 host31 systemd[1]: Starting The Apache HTTP Server... Jul 30 17:27:53 host31 httpd[64517]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.32.31. Set the 'ServerName' directive globally to suppress this message Jul 30 17:27:53 host31 systemd[1]: Started The Apache HTTP Server. [root@host31 ~]# [root@host31 ~]#
确认启动httpd
使用service 停止httpd
[root@host31 ~]# ansible host31 -m service -a "name=httpd state=stopped" host31 | SUCCESS => { "changed": true, "name": "httpd", "state": "stopped" } [root@host31 ~]# ansible host31 -m command -a "systemctl status httpd" host31 | FAILED | rc=3 >> ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:httpd(8) man:apachectl(8) Jul 30 17:24:04 host31 systemd[1]: Starting The Apache HTTP Server... Jul 30 17:24:04 host31 httpd[63250]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.32.31. Set the 'ServerName' directive globally to suppress this message Jul 30 17:24:04 host31 systemd[1]: Started The Apache HTTP Server. Jul 30 17:25:15 host31 systemd[1]: Stopping The Apache HTTP Server... Jul 30 17:25:16 host31 systemd[1]: Stopped The Apache HTTP Server. Jul 30 17:27:53 host31 systemd[1]: Starting The Apache HTTP Server... Jul 30 17:27:53 host31 httpd[64517]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.32.31. Set the 'ServerName' directive globally to suppress this message Jul 30 17:27:53 host31 systemd[1]: Started The Apache HTTP Server. Jul 30 17:35:14 host31 systemd[1]: Stopping The Apache HTTP Server... Jul 30 17:35:15 host31 systemd[1]: Stopped The Apache HTTP Server. [root@host31 ~]#
使用service模块重启httpd并设定开机自启
设定httpd,使得其能开机自启[root@host31 ~]# ansible host31 -m service -a "name=httpd enabled=yes state=restarted" host31 | SUCCESS => { "changed": true, "enabled": true, "name": "httpd", "state": "started" } [root@host31 ~]# ansible host31 -m shell -a "systemctl status httpd" host31 | SUCCESS | rc=0 >> ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2016-07-30 17:38:15 EDT; 24s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 66574 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service tq66574 /usr/sbin/httpd -DFOREGROUND tq66575 /usr/sbin/httpd -DFOREGROUND tq66576 /usr/sbin/httpd -DFOREGROUND tq66577 /usr/sbin/httpd -DFOREGROUND tq66578 /usr/sbin/httpd -DFOREGROUND mq66579 /usr/sbin/httpd -DFOREGROUND Jul 30 17:38:14 host31 systemd[1]: Starting The Apache HTTP Server... Jul 30 17:38:15 host31 httpd[66574]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.32.31. Set the 'ServerName' directive globally to suppress this message Jul 30 17:38:15 host31 systemd[1]: Started The Apache HTTP Server. [root@host31 ~]#
使用yum模块删除httpd
可以看出其能正常remove httpd-2.4.6-40.el7.centos.4.x86_64[root@host31 ~]# ansible host31 -m shell -a "rpm -qa |grep httpd" host31 | SUCCESS | rc=0 >> httpd-2.4.6-40.el7.centos.4.x86_64 httpd-tools-2.4.6-40.el7.centos.4.x86_64 [root@host31 ~]# [root@host31 ~]# ansible host31 -m yum -a "name=httpd state=absent" host31 | SUCCESS => { "changed": true, "msg": "", "rc": 0, "results": [ "Loaded plugins: fastestmirror, langpacks\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nRemoving:\n httpd x86_64 2.4.6-40.el7.centos.4 @updates 9.4 M\n\nTransaction Summary\n================================================================================\nRemove 1 Package\n\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Erasing : httpd-2.4.6-40.el7.centos.4.x86_64 1/1 \n Verifying : httpd-2.4.6-40.el7.centos.4.x86_64 1/1 \n\nRemoved:\n httpd.x86_64 0:2.4.6-40.el7.centos.4 \n\nComplete!\n" ] } [root@host31 ~]# ansible host31 -m shell -a "rpm -qa |grep httpd" host31 | SUCCESS | rc=0 >> httpd-tools-2.4.6-40.el7.centos.4.x86_64 [root@host31 ~]#
相关文章推荐
- 实例学习ansible系列(4)常用模块之command/shell/raw
- 实例学习ansible系列(11)常用模块之get_url/cron/synchronize
- 实例学习ansible系列(5)常用模块之copy
- 实例学习ansible系列(8)常用模块之user/group
- 实例学习ansible系列(10)常用模块之script
- 实例学习ansible系列(12)常用模块之docker
- 实例学习ansible系列(7)常用模块之ping/setup
- 实例学习ansible系列(3)Ansible执行命令常用Option
- ansible学习系列2-ansible常用模块使用
- jsp常用功能模块-JSP实例学习教程
- Ansible系列(二):选项和常用模块
- ansible基础学习,常用模块概述
- Ansible学习:(二)Ansible常用模块详解
- 实例学习ansible系列(14)playbook变量使用
- java分布式系统部署学习(七)ansible 常用模块
- 实例学习ansible系列(16)playbook中自定义环境变量的使用
- jsp常用功能模块-JSP实例学习教程
- jsp常用功能模块-JSP实例学习教程
- jsp常用功能模块-JSP实例学习教程
- 【Ansible学习】- 常用文件操作模块之copy模块