ansible断定文件或者文件夹是否存在

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

相关文章
相关标签/搜索