클라우드/Ansible
Ansible file exists
이쿠우우
2022. 1. 27. 15:49
반응형
파일 exists checking (stat 모듈)
managed node에서 control node로 파일 존재 확인
fetch 모듈 사용.
playbook 예제
---
- hosts: all
remote_user: root
become: true
tasks:
- name: checking if a file exists
stat:
path: /temp/sample.txt
register: file_data
- name: Report if a file exists
when: file_data.stat.exists
debug:
msg: "The file or directory exists"
- name: Report a missing file
when: not file_data.stat.exists
debug:
msg: "The file or directory doesn't exists"
|
조건 문 when 사용함.
playbook 실행
ansible-playbook -i host.ini ./testplaybook
결과로 msg 항목을 통해 파일 유,무를 확인할 수 있음.
반응형