ansibleファイルまたはフォルダが存在するか否か判定

1108 ワード

ansibleの共通モジュールでは、ファイルが存在するか存在しないかを判定していない場合、ある実行を実行するには、次の方法であるファイルが存在するか否かを簡単に判定することができる
---

- name: judge a file or dir is exits
  shell: ls /home/sfy
  ignore_errors: True
  register: result

- shell: echo "file exit"
  when: result|succeeded

- shell: echo "file not exit"
  when: result|failed

もう一つ
# /root/.ssh/id_rsa     ,        
- command: chmod 600 /root/.ssh/id_rsa removes=/root/.ssh/id_rsa

以下を参照してください.https://blog.csdn.net/yushi6310/article/details/78679799
転載先:https://www.cnblogs.com/wynjauu/p/10702517.html