ansible 的經常使用模塊中沒有斷定當文件存在或者不存在時,執行某個執行
使用下面方法能簡單斷定某個文件是否存在shell
--- - 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
另一種ssh
#當/root/.ssh/id_rsa文件存在時,則修改該文件權限 - command: chmod 600 /root/.ssh/id_rsa removes=/root/.ssh/id_rsa
參見:https://blog.csdn.net/yushi6310/article/details/78679799spa