[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
- 目录
- ansible基础
- ansible简介
- ansible安装和测试
- ansible配置文件
- 常用命令
- yaml在ansible中的用法
- inventory
- 变量与facts
- when语句
- handler模块
- 大杂烩
- ansible模块
- assert 模块
- copy模块
- cron模块
- debug模块
- django_manage模块
- file模块
- filesystem模块
- git模块
- hostname模块
- lineinfile模块
- mount模块
- mysql_user模块
- mysql_db模块
- pip模块
- selinux
- setup模块
- shell 和 command 模块
- stat模块
- supervisorctl
- systemd
- timezone
- unarchive模块
- user模块
- wait_for
- yum和service模块
- 其他模块或者方法
- setup模块
- url模块
- slack 模块
- pause 模块
- 其他
- 报错处理
- playbooks
- 复杂的playbook
- 循环
- roles
- YAML
- jinja2