serverapps:configmgmt:ansible:ansibletips
差分
このページの2つのバージョン間の差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
| serverapps:configmgmt:ansible:ansibletips [2017/04/14 05:21] – 外部編集 127.0.0.1 | serverapps:configmgmt:ansible:ansibletips [2020/01/28 02:33] (現在) – [ファイルの存在確認] hayashi | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== AnsibleのTips ====== | ====== AnsibleのTips ====== | ||
| + | ===== DryRun時にスキップ ===== | ||
| + | スキップしたいTASKに以下の条件を付与する | ||
| + | |||
| + | when: not ansible_check_mode | ||
| ===== json形式のstdoutを利用する ===== | ===== json形式のstdoutを利用する ===== | ||
| 行 67: | 行 71: | ||
| コマンドラインで確認するには | コマンドラインで確認するには | ||
| $ ansible-playbook exsample-book.yml --list-host | $ ansible-playbook exsample-book.yml --list-host | ||
| + | ===== ファイルの有無を確認 ===== | ||
| + | |||
| + | <code yaml> | ||
| + | # task | ||
| + | - find: path=/ | ||
| + | register: checked_dir | ||
| + | |||
| + | - fail: | ||
| + | msg=' | ||
| + | when: checked_dir.matched > 0 | ||
| + | |||
| + | - debug: | ||
| + | msg: 'this directory is empty.' | ||
| + | |||
| + | </ | ||
| + | | ||
| ===== ファイルの存在確認 ===== | ===== ファイルの存在確認 ===== | ||
| 行 72: | 行 92: | ||
| # task | # task | ||
| - stat: path=/ | - stat: path=/ | ||
| - | register: | + | register: |
| - name: skip if file is found. | - name: skip if file is found. | ||
| fail: msg=' | fail: msg=' | ||
| - | when: is_exist.stat.md5 is not defined | + | when: checked_file.stat.md5 is not defined |
| + | |||
| + | ## OR | ||
| + | |||
| + | - name: skip if file is found. | ||
| + | fail: msg=' | ||
| + | when: not checked_file.stat.exists | ||
| </ | </ | ||
serverapps/configmgmt/ansible/ansibletips.1492147294.txt.gz · 最終更新: by 127.0.0.1
