Run Ansible script in a multi thread way


I would like to run a simple Ansible script using roles structure against different hosts with their variables stored in different files.
Let's assume that we have host1 and host2 defined as hosts.
As an example, this would be the main roles file(/home/dante/roles/project/main.yml):
--- #New network
- name: network
hosts: host1, host2
gather_facts: false
- /home/dante/roles/project/variables/network-1.yml
- /home/dante/roles/project/variables/network-2.yml
- project
The task file located on /home/dante/roles/project/tasks/main.yml would look like this:
--- #task
- name: Create the networks
cloud: "{{ }}"
state: present
name: "{{ }}"
- "{{ networks }}"
tags: create_networks

1st variable file:
--- # /home/dante/roles/project/variables/network-1.yml
- { cloud: tenant1, network: network-1 }
- { cloud: tenant1, network: network-2 }
2nd variable file:
--- # /home/dante/roles/project/variables/network-2.yml
- { cloud: tenant2, network: network-3 }
- { cloud: tenant2, network: network-4 }

Is any method that would create the Openstack network in an iterated way and per host?  For example, for host1 => to apply the variable files just from network-1.yml and for host 2 => to apply just the variables from network2-2.yml?

Best regards,
  • post-author-pic
    Stosh O

    Hi Dan,

    The only way that occurs to me to do this would be to create a play per host.  I realize this doesn't really scale but it will force a creation order.  Hope this helps!


Looking For Team Training?

Learn More