Example of Multple Ansible Play in One Playbook
---
- name: sample1
hosts: localhost
gather_facts: no
tasks:
- name: sample_task1
debug:
msg: "sample 1 task 1"
- name: sample2
hosts: localhost
gather_facts: no
tasks:
- name: sample_task2
debug:
msg: "sample 2 task 2"Code language: JavaScript (javascript)
Example of Multple Ansible Playbook in One Yaml file
Build many sub-playbooks and aggregate them via include statements.
- include: playbook-one.yml
- include: playbook-two.yml
Note -
include is deprecated. docs.ansible.com/ansible/latest/playbooks_reuse.html import_playbook: foo is the right way to go
For newer versions of Ansilbe, you can build many sub-playbooks and aggregate them via import_playbook statements:
---
- import_playbook: A-systemd-networkd.yml
- import_playbook: B-fail2ban-ssh.yml
- import_playbook: C-enable-watchdog.ymlCode language: PHP (php)
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals