https://www.inflearn.com/course/ansible-%EC%9D%91%EC%9A%A9
ㅇ 앤서블 노드에 nginx 설치 및 테스트 그리고 삭제하기
- nginx_isntall.yaml 작성
# gather_facts 관련
> https://ossian.tistory.com/98
# become => root 권한 획득
# * 기존 yum:
name:
형식(여러줄)과 yum: name= (한줄) 은 동일하게 작용
2 - name: Install nginx on CentOS
3 hosts: CentOS
4 gather_facts: no
5 become: yes
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.yaml 작성
# yum 모듈에서 state를 absent (비어있음) 으로 설정하여 삭제함
1
2 - name: Remove nginx on CentOS
3 hosts: CentOS
4 gather_facts: no
5 become: yes
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
작성 후, # ansible-playbook nginx_install -k 로 실행
ㅇ 시간대(timezone) 변경하기
- timezone.yaml 작성
1 ---
2 - name: Setup linux timezone
3 hosts: CentOS
4 gather_facts: no
5 become: yes
6
7 tasks:
8 - name: set timezone to Asia/Seoul
9 timezone: name=Asia/Seoul
- 적용 및 결과
ㅇ NFS 서버와 클라이언트 구성하기
- nfs.yaml 작성 후 실행!
1
2 - name: Setup for nfs server & clients
3 gather_facts: no
4 hosts: localhost
5
6 tasks:
7 - name: make nfs_shared directory
8 file:
9 path: /home/vagrant/nfs_shared
10 state: directory
11 mode: 0777
12 - name: configure /etc/exports
13 become: yes
14 lineinfile:
15 path: /etc/exports
16 line: /home/vagrant/nfs_shared 192.168.0.0/24(rw,sync)
17
18 - name: nfs service restart
19 become: yes
20 service:
21 name : nfs
22 state : restarted
23
24 - name : Setup for nfs clients
25 hosts: CentOS
26 gather_facts: no
27
28 tasks:
29 - name: make nfs_client directory
30 file:
31 path: /home/vagrant/nfs
32 state: directory
33 - name: mount point directory as client
34 become: yes
35 mount:
36 name: /home/vagrant/nfs
37 src: 192.168.0.10:/home/vagrant/nfs_shared
38 fstype: nfs
39 opts: nfsvers=3
40 state: mounted