Example 1
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
tasks.yml
- name: Task2
debug:
msg: This is Task2
- name: Task3
debug:
msg: This is Task3
playbook.yml
- name: Example playbook
hosts: centos1
gather_facts: false
tasks:
- name: Task1
debug:
msg: This is Task1
- include_tasks: tasks.yml
Tip
Tasks can be defined in seperate files and imported using the include_tasks
directive. This is especially useful if we want to include a certain group of tasks conditionally.
Execute the following command
ansible-playbook playbook.yml