Example 2
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: Task2
debug:
msg: This is Task1
- import_tasks: tasks.yml
Tip
Tasks can also be imported with import_tasks
. The main difference is that the import_*
statements are pre-processed at the time the playbook is parsed, whereas include_*
is parsed in runtime.
Execute the following command
ansible-playbook playbook.yml