Ansible-Puppet-Chef
[ansible] 디렉토리 여부 테스트후 작동
'김용환'
2014. 6. 27. 11:44
디렉토리가 있으면 다른 작업을 하도록 한다.
stat과 when 모듈을 사용하면 된다.
- name: If tomcat1 dir exists
stat: path=/app/tomcat1
register: tomcat_path
- name: If tomcat1 dir exists
debug: msg='tomcat1 dir exist'
when: tomcat_path.stat.exists == true
- name: If tomcat1 dir not exists
debug: msg='tomcat1 did not exist'
when: tomcat_path.stat.exists == false
<실행>
TASK: [tomcat1 | If tomcat1 dir exists] ***************************************
ok: [192.168.1.50]
TASK: [tomcat1 | If tomcat1 dir exists] ***************************************
ok: [192.168.1.50] => {
"item": "",
"msg": "tomcat1 dir exist"
}
TASK: [tomcat1 | If tomcat1 dir not exists] ***********************************
skipping: [192.168.1.50]