gpt4 book ai didi

如果文件存在,则 Ansible 停止剧本

转载 作者:行者123 更新时间:2023-12-04 06:33:46 24 4
gpt4 key购买 nike

如果我的节点上存在定义文件并输出解释剧本停止的原因,是否可以在执行期间停止剧本?

这是为了防止在已经安装了我的应用程序的节点上意外重新执行我的剧本,因为我在此安装过程中生成了密码并且我不想重新初始化此密码。

最佳答案

您可以使用 fail module使用自定义失败消息强制失败。

将此与文件检查结合使用,使用 stat module ,这对你来说应该很容易工作。

一个简单的例子或一个运行手册可能看起来像这样:

- name: check for foo.conf
stat: path=/etc/foo.conf
register: foo

- name: fail if already run on host
fail: msg="This host has already had this playbook run against it"
when: foo.stat.exists

- name: create foo.conf
file: path=/etc/foo.conf state=touch

关于如果文件存在,则 Ansible 停止剧本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37348655/

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