Ansible 倍数包括 "in block"

Ansible multiple includes "in block"

我有一本包含以下内容的剧本:

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

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

- 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')

"include" 也即将贬值。最新最好的(我认为>2.4)是"import_task"

- name: create/update security group, ec2, and elb
  block:
    - import_tasks: security_group.yaml
    - import_tasks: ec2.yaml
    - import_tasks: elb.yaml
  when: STATE == 'present'

编辑:如下所述,"include_task" 而不是 "include"(折旧)或 "import_task"(用例略有不同)是对初始问题的技术正确答案。

- name: create/update security group, ec2, and elb
  block:
    - include_tasks: security_group.yaml
    - include_tasks: ec2.yaml
    - include_tasks: elb.yaml
  when: STATE == 'present'