Run Ansible script in a multi thread way

Hi,

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
vars_files:
- /home/dante/roles/project/variables/network-1.yml
- /home/dante/roles/project/variables/network-2.yml
 roles:
- project
The task file located on /home/dante/roles/project/tasks/main.yml would look like this:
--- #task
- name: Create the networks
os_network:
cloud: "{{ item.cloud }}"
state: present
name: "{{ item.network }}"
with_items:
- "{{ networks }}"
tags: create_networks

1st variable file:
--- # /home/dante/roles/project/variables/network-1.yml
networks:
- { cloud: tenant1, network: network-1 }
- { cloud: tenant1, network: network-2 }
2nd variable file:
--- # /home/dante/roles/project/variables/network-2.yml
networks:
- { 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,
Dan
 
  • post-author-pic
    Stosh O
    09-28-2018

    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!

    -Stosh

Looking For Team Training?

Learn More