1. 기본 playbook 형식
2. nginx 설치
3. 핸들러
4. when
5. loop
6. role
[1. 기본 playbook 형식]
---
- name: ex
hosts: all # host
become: yes # root 권한 부여
tasks # 모듈 실행
[2. nginx 설치]
---
- name: nginx 설치
become: yes
hosts: webserver
tasks:
- name: install_webserver
apt:
name: nginx
state: present
- name: start_werbserver
systemd:
name: nginx
state: started
enabled: yes
[3. 핸들러 ]
---
tasks:
- name: nginx
copy:
src: nginx.conf
dest: /etc/nginx/nginx.conf
mode: 700
notify: nginx_started
handlers:
- name: nginx_started
systemd:
name: nginx
state: started
enabled: yes
[4. when]
tasks:
- name: install_nginx when os version is debian
apt:
name: nginx
state: present
when: ansible_os_family == "Debain"
[5. loop]
tasks:
- name: install git and nginx and curl
apt:
name: "{{item}}"
state: present
loop:
- curl
- nginx
- git
'공부 > Ansible' 카테고리의 다른 글
25 04 13 공부 (0) | 2025.04.15 |
---|---|
25 04 10 ansible 학습 (0) | 2025.04.10 |
4. Ansible의 기본 명령어 (0) | 2025.03.28 |
3. 에이전트리스 방식이란? (0) | 2025.03.27 |
2. Yaml 기본 문법 (0) | 2025.03.27 |