角色的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
在这种情况下,如何在不修改每个 role
的情况下使用 vars_prompt
?
How can I use vars_prompt
in this case without modify every role
?
推荐答案
如果使用 vars_prompt
查看运行剧本的输出,您会发现失败
任务在其他角色之后运行.有关剧本和角色的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屋!