Ansible Module - Services



ステータス値

  • started–サービスを開始します.必要な時だけ行動する.
  • -サービスを停止します.必要な時だけ行動する.
  • 再起動–常にサービスを再起動します.
  • 再ロード–サービスの実行を中断せず、変更された設定のみが適用されます.
  • - hosts: web1
      tasks:
      - service:
          name: httpd
          state: started
    Make changes in the playbook so that httpd server reloads after copying the file, make sure it does not restart the httpd server.
    - hosts: all
      gather_facts: no
      tasks:
        - name: Copy Apache welcome file
          copy:
            src: index.html
            dest: /var/www/html/index.html
        - name: reload
          service:
            name: httpd
            state: reloaded
    port: 80. →443変更後にhttpサービスを再起動する
    - hosts: all
      gather_facts: no
      tasks:
        - name: Make changes in Apache config
          replace:
            path: /etc/httpd/conf/httpd.conf
            regexp: "^Listen 80"
            replace: "Listen 443"
    
        - name: Restart Apache
          service:
            name: httpd
            state: restarted
    Nginxをインストールし、再起動するたびに自動的に実行
    ---
    - name: nginx
      gather_facts: no
      hosts: web1
      tasks:
        - name: install nginx
          yum:
            name: nginx
            state: installed
    
        - name: restart
          service:
            name: nginx
            state: started
            enabled: yes