문제
현재 Playbook 의 호스트가 특정 그룹에 속하지 않는 경우에만 재발 할 수있는 작업을 실행하고 싶습니다.세미 의사 코드 :
- name: my command
command: echo stuff
when: "if {{ ansible_hostname }} not in {{ ansible_current_groups }}"
.
어떻게해야합니까?
해결책
여기를 수행하는 또 다른 방법은 다음과 같습니다.
- name: my command
command: echo stuff
when: "'groupname' not in group_names"
.
group_names
는 여기에 문서화 된 마법 변수입니다. http://docs.ancible.com/playbook_variables.html#magic-variables-and-how-to-access-information-aboutother-hosts :
group_names는 현재 호스트가있는 그룹의 모든 그룹의 목록 (배열)입니다.
다른 팁
group_vars/
에있는 vars 파일의 제어 변수를 설정하거나 다음과 같이 호스트 파일에 직접 설정할 수 있습니다.
[vagrant:vars]
test_var=true
[location-1]
192.168.33.10 hostname=apollo
[location-2]
192.168.33.20 hostname=zeus
[vagrant:children]
location-1
location-2
.
다음과 같이 작업을 실행하십시오 :
- name: "test"
command: "echo {{test_var}}"
when: test_var is defined and test_var
. 제휴하지 않습니다 StackOverflow