Ansible multiple includes "in block"

I have a player with enabled:

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

Is it possible not to repeat the condition? I tried to block, but it seems that blocks cannot be used in this context:

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

Is there any way to do this? I also tried something like

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

which also does not work

+4
source share
2 answers

This syntax works fine in inaccessible 2.1.1 (exact indentation):

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

"include" will soon also depreciate. The last and best (> 2.4, I think) is "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'
0
source

Source: https://habr.com/ru/post/1651603/


All Articles