Slide 1
Most trusted JOB oriented professional program
DevOps Certified Professional (DCP)

Take your first step into the world of DevOps with this course, which will help you to learn about the methodologies and tools used to develop, deploy, and operate high-quality software.

Slide 2
DevOps to DevSecOps – Learn the evolution
DevSecOps Certified Professional (DSOCP)

Learn to automate security into a fast-paced DevOps environment using various open-source tools and scripts.

Slide 2
Get certified in the new tech skill to rule the industry
Site Reliability Engineering (SRE) Certified Professional

A method of measuring and achieving reliability through engineering and operations work – developed by Google to manage services.

Slide 2
Master the art of DevOps
Master in DevOps Engineering (MDE)

Get enrolled for the most advanced and only course in the WORLD which can make you an expert and proficient Architect in DevOps, DevSecOps and Site Reliability Engineering (SRE) principles together.

Slide 2
Gain expertise and certified yourself
Azure DevOps Solutions Expert

Learn about the DevOps services available on Azure and how you can use them to make your workflow more efficient.

Slide 3
Learn and get certified
AWS Certified DevOps Professional

Learn about the DevOps services offered by AWS and how you can use them to make your workflow more efficient.

previous arrow
next arrow

Ansible include scenario with list of plays or tasks

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
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x