728x90

실습 과정

- 앤서블 서버에서 작업

1. 설치 (nginx_install.yml)

2. 파일 전송

3. 서비스 재시작

4. 삭제 (nginx_remove.yml)

 

앤서블 서버에서 nginx_install.yml 파일 생성

  1 ---
  2 - name: Install nginx on CentOS
  3   hosts: CentOS # node01, node02를 지칭함
  4   gather_facts: no
  5   become: yes # root 권한 부여
  6
  7   tasks:
  8     - name: install epel-release
  9       yum: name=epel-release state=latest
 10     - name: install nginx web server
 11       yum: name=nginx state=present
 12     - name: Upload default index.html for web server
 13       get_url: url=https://www.nginx.com dest=/usr/share/nginx/html/ mode=0644
 14     - name: Start nginx web server
 15       service: name=nginx state=started

 

앤서블 서버에서 nginx_remove.yml 파일 생성

  1 ---
  2 - name: Remove nginx on CentOS
  3   hosts: CentOS # node01, node02를 지칭함
  4   gather_facts: no
  5   become: yes # root 권한 부여
  6
  7   tasks:
  8     - name: remove epel-release
  9       yum: name=epel-release state=absent
 10     - name: remove nginx web server
 11       yum: name=nginx state=absent

 

플레이북을 이용해 각각의 노드에 nginx 설치

[vagrant@ansible-server ~]$ anp nginx_install.yml -k
SSH password: # vagrant

PLAY [Install nginx on CentOS] ***************************************************************

TASK [install epel-release] ******************************************************************
changed: [node02]
changed: [node01]

TASK [install nginx web server] **************************************************************
changed: [node01]
changed: [node02]

TASK [Upload default index.html for web server] **********************************************
changed: [node01]
changed: [node02]

TASK [Start nginx web server] ****************************************************************
changed: [node02]
changed: [node01]

PLAY RECAP ***********************************************************************************
node01                     : ok=4    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
node02                     : ok=4    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

웹 브라우저에서 노드의 IP 주소로 접속하여 nginx 기본 페이지 확인

 

 

nginx 삭제

[vagrant@ansible-server ~]$ anp nginx_remove.yml -k
SSH password: # vagrant

PLAY [Remove nginx on CentOS] ****************************************************************

TASK [remove epel-release] *******************************************************************
changed: [node01]
changed: [node02]

TASK [remove nginx web server] ***************************************************************
changed: [node02]
changed: [node01]

PLAY RECAP ***********************************************************************************
node01                     : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
node02                     : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

 

728x90

+ Recent posts