Skip to content

Example 4

hosts.yml

centos:
  hosts:
    provisioner:
      ansible_connection: local
    centos1:
      ansible_host: '192.168.77.22'
ubuntu:
  hosts:
    ubuntu1:
      ansible_host: '192.168.77.23'

extra.yml

- name: extra
  hosts: ubuntu1
  gather_facts: false
  tasks:
    - name: Task2
      debug:
        msg: Task2 in extra

main.yml

- name: main
  hosts: centos1
  gather_facts: false
  tasks:
    - name: Task1
      debug:
        msg: Task1 in main
- import_playbook: extra.yml

Tip

The mechanisms of include_* and import_* are not limited to the tasks scope. The user can import/include whole playbooks or roles.

Execute the following command

ansible-playbook main.yml