Ansibleにおいて表題を行う。ディレクトリが存在する場合はスキップしたい処理がある。
■ 環境
- Ansible 2.2.2.0
■ stat
stat – retrieve file or file system status
http://docs.ansible.com/ansible/stat_module.html
下記のように書ける。
- name: directory check
stat:
path: /path/to/directory
register: d
- name: skip task
debug:
msg: "skip skip skip"
when:
- d.stat.exists
- d.stat.isdir
このように書くことが可能である。条件としては2つ入れてみた。
- “/path/to/directory“が存在する
- “/path/to/directory“がディレクトリである
これら2つの条件が共に真である場合に、”debug“モジュールで指定した”msg“が出力される。
以上。