Ansible Module - Services

CodingDaddy·2022년 3월 19일
0

Ansible -Study

목록 보기
6/11
post-thumbnail

State 값

  • started – 서비스를 시작합니다. 필요한 경우만 동작한다.
  • stopped – 서비스를 종료합니다. 필요한 경우만 동작한다.
  • restarted – 항상 서비스를 재시작 한다.
  • reloaded – 서비스 실행을 중단하지 않고 변경된 설정만 적용한다.
- 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 변경 후 httpf 서비스 재시작

- 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
profile
Creative - DevOps in Korea

0개의 댓글