Ansible 多个包含 "in block"

标签 ansible ansible-2.x

我有一本剧本,其中包括:

- include: include1.yml
  when: doinclude | default('true')
- include: include2.yml
  when: doinclude | default('true')

是否有可能不重复该条件?我尝试了 block ,但似乎 block 不能在该上下文中使用:

- block:
  - include: include1.yml
  - include: include2.yml
  when: doinclude  | default('true')

有什么办法可以做到这一点吗?我也尝试过类似的东西

- name: test
  hosts: all
  tasks:
    - block:
      - include: include1.yml
      - include: include2.yml
    when: doinclude  | default('true')

这也不起作用

最佳答案

此语法在 ansible 2.1.1 中运行良好(缩进准确):

---
- hosts: localhost
  tasks:
    - block:
        - include: include1.yml
        - include: include2.yml
      when: doinclude | default('true')

关于Ansible 多个包含 "in block",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39005248/

相关文章:

Ansible get_url 超时

ansible - 失败! => {"msg": "' failed' is not a valid option in debug"}

ssh - ansible 剧本 [设置] 收集事实 - SSH UNREACHABLE 连接在横幅期间超时

Ansible 处理程序和 shell 模块

ansible - ansible 中的冲突操作声明

ansible - 想要在远程主机上运行ansible任务

ansible - 为 playbook 中的每个 Ansible 任务提供描述

ansible - 我可以从具有动态名称的角色导入特定任务吗?

shell - ansible with_first_found 不工作

amazon-web-services - 来自复杂结构的 Ansible 查找值?