Slide 1
Excellent Education Program
Innovative Methods of Teaching

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cum sociis natoque penatibus et magnis dis parturient.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 2
Learning Through Play
Devoted to the Early Education

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.

Slide 3
Learning Through Play
Find a Class for your Children

Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis.

previous arrow
next arrow

Ansible include scenario with list of plays or tasks

Spread the Knowledge

Are you trying to use include in your playbook and coming across a error somthing like “A playbook must be a list of plays”. That means you are at right url.

include help you to Includes a file with a list of plays or tasks to be executed in the current playbook. Files with a list of plays can only be included at the top level. Lists of tasks can only be included where tasks normally run (in play).

With include on the task level Ansible expects a file with tasks only, not a full playbook.

------main.yaml------------
- hosts: all
  tasks:
    - debug:
        msg: task1

    - name: Include task list in play
      include: stuff.yaml

------stuff.yaml------------
---
- name: http service state
  service: name=httpd state=started enabled=yes

With include on the task level Ansible expects a file with tasks only, not a full playbook.

------main.yaml------------
- hosts: all
  tasks:
    - debug:
        msg: task1

    - include: stuff.yaml


------stuff.yaml------------
---
- name: http service state
  service: name=httpd state=started enabled=yes

With include on the play level Ansible expects a playbook with hosts/tasks spec. i.e full playbook.

------main.yaml------------
- hosts: all
  tasks:
    - debug:
        msg: task1

- include: stuff.yaml


------stuff.yaml------------
---
- hosts: web
  tasks:
    - debug:
        msg: task1
    - name: http service state
      service: name=httpd state=started enabled=yes

Example of include calling common tasks.

# my_tasks.yml
- name: Check PID of existing Java process
  shell: "ps -ef | grep [j]ava"
  register: java_status

  - debug: var=java_status.stdout

# check_java_pid.yml
---
- hosts: all
  gather_facts: no

  tasks:
    - include my_tasks.yml

# instance_restart.yml
---
- hosts: instance_1
  gather_facts: no

  tasks:
    - include: my_tasks.yml

Some of more example using Condition

---
tasks:
  - include install_postgres.yml
    when: db == "Y"
Rajesh Kumar