gpt4 book ai didi

ansible - 简化可靠的文件检查?

转载 作者:行者123 更新时间:2023-12-01 11:36:52 25 4
gpt4 key购买 nike

在 ansible 中我做了很多这样的事情:

- name: Check if [someFile] exists on host
stat: path=[someFile]
register: someFile

- fail: msg="[someFile] not found"
when: someFile.stat.exists == False

我希望能够更简洁地表达它。像这样:

- fail_on_missing_file: 
path: [someFile]

实现此目标的最佳方法是什么?

最佳答案

你可以使用failed_when来做你想做的事:

- stat: path=/path/to/some/file
register: someFile
failed_when: not someFile.stat.exists

关于ansible - 简化可靠的文件检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26056868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com