💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[stat模块官方文档][1] stat模块和linux的stat命令实现的功能相同 ### 常用示例 ~~~ - stat: path: /etc/foo.conf register: st - fail: msg: "Whoops! file ownership has changed" when: st.stat.pw_name != 'root' # 检测path是否存在并且是符号链接,如果path不存在,直接检测sym.stat.islnk会报错;因此,先检测sym.stat.islnk是否定义 - stat: path: /path/to/something register: sym - debug: msg: "islnk isn't defined (path doesn't exist)" when: sym.stat.islnk is not defined - debug: msg: "islnk is defined (path must exist)" when: sym.stat.islnk is defined - debug: msg: "Path exists and is a symlink" when: sym.stat.islnk is defined and sym.stat.islnk - debug: msg: "Path exists and isn't a symlink" when: sym.stat.islnk is defined and sym.stat.islnk == False # 检测目录是否存在 - stat: path: /path/to/something register: p - debug: msg: "Path exists and is a directory" when: p.stat.isdir is defined and p.stat.isdir ~~~ 还有exists方法 [1]:http://docs.ansible.com/ansible/latest/stat_module.html