gpt4 book ai didi

Ansible vars_prompt 角色

转载 作者:行者123 更新时间:2023-12-04 15:09:30 27 4
gpt4 key购买 nike

我有一套Ansible playbooks 和主要的 yml 文件是这样的

- hosts: all 
roles:
- common
- install_nginx

我想在触发剧本时添加确认消息。我试过这个但没有用
- hosts: all
vars_prompt:
- name: CONFIRM
prompt: Just to confirm you will install stuff
tasks:
- fail: no deployment this time
when: CONFIRM != 'yes'
roles:
- common
- install_nginx

我如何使用 vars_prompt在这种情况下,无需修改每个 role ?

最佳答案

如果您使用 vars_prompt 查看运行剧本的输出你会看到 fail任务在其他角色之后运行。这在Ansible docs for playbooks and roles中也有提到:

If the play still has a ‘tasks’ section, those tasks are executed after roles are applied.



正如上面的文档还提到,如果您想强制任务在任何角色之前运行,那么您可以使用 pre_tasks .

因此,要让您的确认风格提示您可以简单地执行以下操作:
- hosts: all
vars_prompt:
- name: CONFIRM
prompt: Just to confirm you will install stuff
pre_tasks:
- fail: no deployment this time
when: CONFIRM != 'yes'
roles:
- common
- install_nginx

关于Ansible vars_prompt 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34504663/

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