티스토리 뷰
Ansible ‘When’ Statement: Check If Variable Is…
Check if Ansible variable is defined (exists):
tasks:
- shell: echo "The variable 'foo' is defined: '{{ foo }}'"
when: foo is defined
- fail: msg="The variable 'bar' is not defined"
when: bar is undefined
Check if Ansible variable is empty:
tasks:
- fail: msg="The variable 'bar' is empty"
when: bar|length == 0
- shell: echo "The variable 'foo' is not empty: '{{ foo }}'"
when: foo|length > 0
Check if Ansible variable is defined and not empty:
tasks:
- shell: echo "The variable 'foo' is defined and not empty"
when: (foo is defined) and (foo|length > 0)
- fail: msg="The variable 'bar' is not defined or empty"
when: (bar is not defined) or (bar|length == 0)
Check if Ansible variable is True or False:
tasks:
- shell: echo "The variable 'foo' is 'True'"
when: foo|bool == True
- shell: echo "The variable 'bar' is 'False'"
when: bar|bool == False
https://www.shellhacks.com/ansible-when-variable-is-defined-exists-empty-true/
'DevOps > Ansible' 카테고리의 다른 글
Ansible: 특정 패턴의 파일들을 찾아서 삭제하기 (0) | 2022.10.05 |
---|---|
Ansible Vault 사용법 (0) | 2019.09.11 |
How to use Ansible Vault (0) | 2019.09.11 |
Ansible: UNREACHABLE!: Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password,keyboard-interactive) (0) | 2019.04.26 |
Ansible: Yaml 데이터 출력 시 앞에 u 붙을 경우 제거하는 방법 (0) | 2019.01.25 |
Include Playbook (Playbook 에서 Playbook 인클루드) (0) | 2018.08.27 |
[Ansible/엔시블/엔서블] Ansible 교육 자료 - 02. Playbooks (1) | 2018.08.23 |
[Ansible/엔시블/엔서블] Ansible 교육 자료 - 01. Introduction (2) | 2018.08.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- iTerm2
- Config History
- 쉘스크립트
- Linux
- openssl
- 엔서블
- 파이프라인
- JVM
- Thread Dump
- DevOps
- Ansible
- ssl
- Playbook
- 데브옵스
- 플레이북
- Jenkins
- URL Encoding
- Shell Script
- 엔시블
- Password manager
- 리눅스
- PostgreSQL
- vagrant
- 쓰레드덤프
- 젠킨스
- groovy
- Docker
- Nexus
- rsync
- nginx
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 |
28 | 29 | 30 |
글 보관함