Ansible vars_prompt 角色

标签 ansible

我有一套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/

相关文章:

python - 可靠的 : You should rebuild using libgmp >= 5 to avoid timing attack vulnerability

yaml - YAML 中的 Ansible 整数变量

ssh - Ansible:检查我的用户是否存在于远程主机上,否则使用root用户与ssh连接

mysql - 来自 MySQL DB 的 Ansible list

version-control - 防止 brew cleanup 删除特定的旧版本软件

docker - 使用 Ansible docker_service 模块将服务部署到 swarm

ansible - 无法将纪元转换为ansible中可读的格式

ansible - 在 Ansible 中如果没有 sudo 则无法 ping 主机

Ansible - 加载 block 时遇到格式错误的 block

ansible - 剧本中的 Vars_prompt