[ANSIBLE] - PLAYBOOK 작성

playbook :
설정파일(YAML)에 미리 정의하여 원격 노드서버의 구성 및 배포를 관리 할수있다.


example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
- hosts: webservers # /etc/ansible/hosts에 정의된 [webservers] 그룹
vars:
http_port: 80
max_clients: 200
remote_user: root # 작업유저
tasks: # 작업리스트
- name: ensure apache is at the latest version
yum: # 패키지 설치
name: httpd
state: latest
- name: write the apache config file
template: # 파일 복사
src: /srv/httpd.j2
dest: /etc/httpd.conf
notify: # handlers 노티
- restart apache
- name: ensure apache is running
service: #서비스 실행
name: httpd
state: started
handlers: # 노티를 listen
- name: restart apache
service:
name: httpd
state: restarted

작성된 playbook 실행

1
ansible-playbook playbook.yml -f 10 # 병렬처리 레벨 10

팁 명령어 옵션 –syntax-check flag
에러 체크해쥼

ansible-playbook playbook.yml –list-hosts # host 목록확인

참고: https://docs.ansible.com/ansible/latest/user_guide/playbooks.html
playbook 문법: https://taesany.tistory.com/139