ansible playbook中的stat和我们日常在linux中使用的stat有着类似的地方,比如如下这个例子:
1 2 3 4 |
- stat: path=/etc/foo.conf register: st - fail: msg="Whoops! file ownership has changed" when: st.stat.pw_name != 'root' |
首先,stat需要一个文件路径,然后,我们就恶意取到这个文件的相关属性,并讲这个文件属性对象赋值给st
然后,我们在对st进行判断,当st.stat.pw_name 不是root的时候,打印出:”Whoops! file ownership has changed”
这个地方有一个fail模块,并不是我们理解的,当st.stat.pw_name != ‘root’ 失败的时候,我们打印信息,它的作用是:
终止当前的进程,并打印信息
上边的例子就是当st.stat.pw_name != ‘root’ 成立的时候,这个playbook就不执行里,然后打印出相关错误信息”Whoops! file ownership has changed”
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021