首页 > 其他 > 详细

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

时间:2019-04-13 20:00:31      阅读:2115      评论:0      收藏:0      [点我收藏+]

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

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

原文:https://www.cnblogs.com/wynjauu/p/10702517.html

(6)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!