ユーザ用ツール

サイト用ツール


serverapps:configmgmt:ansible:ansibletips

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
serverapps:configmgmt:ansible:ansibletips [2017/04/14 14:21]
127.0.0.1 外部編集
serverapps:configmgmt:ansible:ansibletips [2020/01/28 11: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=/path/to/folder
 +  register: checked_dir
 +
 +- fail:
 +    msg='this directory is not empty. file exists'
 +  when: checked_dir.matched > 0
 +
 +- debug:
 +    msg: 'this directory is empty.'
 +
 +</code>
 +  
 ===== ファイルの存在確認 ===== ===== ファイルの存在確認 =====
  
行 72: 行 92:
 # task # task
 - stat: path=/path/to/anyfile - stat: path=/path/to/anyfile
-  register: is_exist+  register: checked_file
  
 - name: skip if file is found. - name: skip if file is found.
   fail: msg='file not found'   fail: msg='file not found'
-  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='file not found' 
 +  when: not checked_file.stat.exists 
 </code> </code>
  
serverapps/configmgmt/ansible/ansibletips.1492147294.txt.gz · 最終更新: 2017/04/14 14:21 by 127.0.0.1