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'
playbook.yml
- hosts: all
gather_facts: false
tasks:
- name: 1st sleep
command: sleep 5
when: inventory_hostname == 'provisioner'
- name: 2nd sleep
command: sleep 5
when: inventory_hostname == 'centos1'
- name: 3rd sleep
command: sleep 5
when: inventory_hostname == 'ubuntu1'
- name: 4th sleep
command: sleep 5
when: inventory_hostname == 'provisioner'
- name: 5th sleep
command: sleep 5
when: inventory_hostname == 'centos1'
Tip
Ansible's parallelism, by default, is limited to the task level and a predefined number of forks
.
Execute the following command
time ansible-playbook playbook.yml
Do you expect to see improved results compared to Example 1?
No, because we will still have to wait for the task to finish on the assigned host during each step.