6

Ansible 如何检查一个文件夹是否存在

 2 years ago
source link: https://www.lfhacks.com/tech/ansible-check-directory-exists/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ansible 如何检查一个文件夹是否存在

2022-06-07
346.jpg
扫一扫,转发文章 ansible-check-directory-exists.png

Ansible 如何检查一个文件夹是否存在

假如希望检查远程主机上某个文件夹是否存在,如何用 ansible 实现?

如果文件夹的路径是 /some/path,保存在 basedir 变量里,我们希望检查这个文件夹是否存在,如果不存在,则报错

可以用下面这个task:

- name: checking dir ansible.builtin.stat: path: "{{ basedir }}" register: basedir_stat failed_when: not (basedir_stat.stat.exists and basedir_stat.stat.isdir)...

这里的 failed_when 条件确保 basedir_stat 同时满足 “文件夹” 和 “存在” 两种状态

为了保证阅读体验,本站不安放广告。但是,租用服务器和编写文章需要个人资金和时间的投入。

如果您觉得文章对您有用,请考虑捐助小站(金额不限),以期待更多原创文章。捐助记录

wechatpay.pngalipay.png
cc-by-nc.gif

本站是个人网站,若无特别说明,文章均为原创,并采用 署名协议 CC-BY-NC 授权。
欢迎转载,惟请保留原文链接,且不得用于商业用途。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK