컬쥐네 다락방
Ansible | 블록과 태그 본문
블록
블록 = 여러 작업을 묶어 놓은 그룹
블록의 기능
- 여러 작업에 공통의 키워드를 부여할 수 있음(ex: 조건문)
block
,rescue
,always
블록을 이용해 오류 처리를 할 수 있음
block
블록은 항상 실행rescue
는 block
블록의 오류가 있을 때만 실행always
는 항상 실행
- hosts: 192.168.100.11
tasks:
- block:
- debug:
msg: hello world
- command: /usr/bin/false
- debug:
msg: hello world2
ignore_errors: yes
rescue:
- debug:
msg: It's rescue
always:
- debug:
msg: It's Always
태그
작업에 태그를 부여하고, 특정 태그의 작업만 실행할 수 있음
- hosts: 192.168.100.11
gather_facts: no
tasks:
- debug:
msg: "web server stage"
tags:
- stage
- debug:
msg: "web server product"
tags:
- prod
- debug:
msg: "web server all"
all 태그: 모든 작업이 속함
untagged 태그: 태그가 설정되어 있지 않는 작업 속함
ansible-playbook test.yaml --tags=stage,prod
태그 관련 확인
ansible-playbook test.yaml --list-tasks
ansible-playbook test.yaml --list-tags
작업 제어
step
ansible-playbook test.yaml --step
특정 작업 부터 시작
ansible-playbook test.yaml --start-at-task="task3"
ansible-playbook test.yaml --start-at-task="task3" --limit 192.168.100.12
'클라우드 > Ansible' 카테고리의 다른 글
Ansible | 아티펙트(Artifact)의 재사용 - 파일 (0) | 2022.04.21 |
---|---|
Ansible | 템플릿 주석 (0) | 2022.04.21 |
Ansible | 조건문과 핸들러 (0) | 2022.04.18 |
Ansible | 반복문 (0) | 2022.04.18 |
Ansible | Ansible 명령에서의 변수 활용 (0) | 2022.04.18 |
Comments