ansible service模块


service 模块:
示例一、启动httpd服务
# ansible 192.168.85.251 -m service -a "name=httpd state=started" -i hosts
示例二、重载httpd服务
# ansible 192.168.85.251 -m service -a "name=httpd state=reloaded" -i hosts
示例三、重启Httpd服务
ansible 192.168.85.251 -m service -a "name=httpd state=restarted" -i hosts
示例四、停止httpd服务
ansible 192.168.85.251 -m service -a "name=httpd state=stopped" -i hosts
示例五、 启动httpd服务,并加入开机自启
ansible 192.168.85.251 -m service -a "name=httpd state=started enabled=yes" -i hosts
[root@blog ~/project1 23:48:05]$ansible 192.168.85.251 -m service -a "name=httpd enabled=yes" -i hosts
[root@blog ~/project1 23:48:05]$ansible 192.168.85.251 -m service -a "name=httpd enabled=no" -i hosts
[root@sh_proxy html]# systemctl is-enabled httpd
disabled
[root@sh_proxy html]# systemctl is-enabled httpd
enabled
[root@sh_proxy html]#
[root@blog ~/project1 23:52:11]$vim first.yml
[root@blog ~/project1 23:58:29]$cat first.yml
---

- hosts: 192.168.85.251
  tasks:
    - name: Install httpd Server
      yum: name=httpd state=present
      # name: httpd
      # state: present

    - name: Configure Httpd Server
      copy: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf backup=yes
      notify: Restart Httpd Server

    - name: Systemd Httpd server
      service: name=httpd state=started enabled=yes


  handlers:
    - name: Restart Httpd Server
      service: name=httpd state=restarted
[root@blog ~/project1 23:59:32]$vim httpd.conf
[root@blog ~/project1 23:59:51]$grep -i ‘^listen httpd.conf
[root@blog ~/project1 00:00:13]$grep -i ‘^listen’ httpd.conf
[root@blog ~/project1 00:00:19]$grep -i ‘^^Csten’ httpd.conf
[root@blog ~/project1 00:00:31]$vim httpd.conf
[root@blog ~/project1 00:00:39]$grep -i '^listen' httpd.conf
Listen 9990
[root@blog ~/project1 00:00:52]$ansible-playbook first.yml -i hosts

PLAY [192.168.85.251] *******************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [192.168.85.251]

TASK [Install httpd Server] *************************************************************************************************************************************************************************************
ok: [192.168.85.251]

TASK [Configure Httpd Server] ***********************************************************************************************************************************************************************************
changed: [192.168.85.251]

TASK [Systemd Httpd server] *************************************************************************************************************************************************************************************
changed: [192.168.85.251]

RUNNING HANDLER [Restart Httpd Server] **************************************************************************************************************************************************************************
changed: [192.168.85.251]

PLAY RECAP ******************************************************************************************************************************************************************************************************
192.168.85.251 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

[root@blog ~/project1 00:01:30]$


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM