Ansible vars_prompt 角色 [英] Ansible vars_prompt for roles
问题描述
我有一套 Ansible
剧本,主要的 yml 文件是这样的
I have a set of Ansible
playbooks and the main yml file is like this
- hosts: all
roles:
- common
- install_nginx
我想在触发剧本时添加确认消息.我试过了,没有用
I want to add the confirm message when I trigger the playbook. I tried this and did not work
- 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
?
How can I use vars_prompt
in this case without modify every role
?
推荐答案
如果您查看使用 vars_prompt
运行剧本的输出,您将看到 fail
> 任务在其他角色之后运行.适用于剧本和角色的 Ansible 文档 中也提到了这一点:
If you look at the output from running your playbook with the vars_prompt
you'll see that the fail
task runs after the other roles. This is also mentioned in the Ansible docs for playbooks and roles:
如果剧本还有任务"部分,则执行这些任务应用角色后.
If the play still has a ‘tasks’ section, those tasks are executed after roles are applied.
正如上面的文档还提到,如果你想强制一个任务在任何角色之前运行,那么你可以使用 pre_tasks
.
As the above docs also mention if you want to force a task to run before any roles then you can use pre_tasks
.
因此,要获得确认样式提示,您可以简单地执行以下操作:
So to have your confirmation style prompt you could simply do this:
- 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 角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!