Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible multiple includes "in block"

I have a playbook with includes:

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

Is there any possibility not to repeat the condition? I tried blocks but it seems blocks cannot be used in that context:

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

Is there any way to do that? 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

like image 968
user140547 Avatar asked Aug 17 '16 19:08

user140547


1 Answers

This syntax works fine in ansible 2.1.1 (be accurate with indentation):

---
- hosts: localhost
  tasks:
    - block:
        - include: include1.yml
        - include: include2.yml
      when: doinclude | default('true')
like image 108
Konstantin Suvorov Avatar answered Sep 28 '22 17:09

Konstantin Suvorov