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