Example 3
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
playbook.yml
- hosts: all
gather_facts: false
tasks:
- name: 1st sleep
command: sleep 20
when: inventory_hostname == 'provisioner'
async: 45
poll: 0
- name: 2nd sleep
command: sleep 5
when: inventory_hostname == 'centos1'
async: 10
poll: 0
- name: 3rd sleep
command: sleep 5
when: inventory_hostname == 'ubuntu1'
async: 10
poll: 0
- name: 4th sleep
command: sleep 5
when: inventory_hostname == 'provisioner'
async: 10
poll: 0
- name: 5th sleep
command: sleep 5
when: inventory_hostname == 'centos1'
async: 10
poll: 0
Tip
The user can introduce the fire & forget
behavior using async
and poll
directives.
Execute the following command
time ansible-playbook playbook.yml
Do you expect to see improved results compared to Example 1?
Yes, because Ansible will exit before the tasks are actually finished running.