Parallel VM Creations

348 views
Skip to first unread message

Chethan S

unread,
Dec 19, 2016, 10:18:28 AM12/19/16
to Ansible Project
Is it possible to create multiple VMs in parallel? As of now, it's one VM after another. I use the vmware_guest module for creating VMs in vCenter Server. 

I tried specifying strategy: free but that is not helping. 

Brian Coca

unread,
Dec 20, 2016, 10:21:04 AM12/20/16
to ansible...@googlegroups.com
if the source of data of your VMs is with_, it will be serial, if you use inventory and hosts: it will be parallel.


----------
Brian Coca

Mark Phillips

unread,
Dec 20, 2016, 2:49:08 PM12/20/16
to Ansible Project
On Monday, 19 December 2016 15:18:28 UTC, Chethan S wrote:
Is it possible to create multiple VMs in parallel? As of now, it's one VM after another. I use the vmware_guest module for creating VMs in vCenter Server. 

I tried specifying strategy: free but that is not helping. 

Funnily enough I had this conversation with somebody on the Twitters a while back. I suggested 'getting clever' with inventory (as Brian alludes to too, actually).

Here's an example …


 

Brian Coca

unread,
Dec 20, 2016, 2:53:01 PM12/20/16
to ansible...@googlegroups.com
I was going for even simpler:

# inventory

[vm_group]
host[1-50] ansible_connection=local

# play
- hosts: vm_group
  gather_facts: false
  tasks:
    - create_vm: name={{inventory_hostname} ....
      delegate_to: localhost

 
----------
Brian Coca

Mark Phillips

unread,
Dec 20, 2016, 2:55:19 PM12/20/16
to Ansible Project

On Tuesday, 20 December 2016 19:53:01 UTC, Brian Coca wrote:
I was going for even simpler:

Dude, you rock!

Chethan S

unread,
Dec 21, 2016, 6:38:59 AM12/21/16
to Ansible Project
Thank you very much, Brian and Mark. I have been using the with_items approach and providing the VM names from a static file. Since we use Ansible Tower, these files are fetched from a git repository. We also use the roles way of doing things and being relatively new to Ansible, I am little confused about how to go ahead here.

I believe in your cases, you define the hostnames in the hosts file saved inside the Ansible Server or a common location. I was trying to figure out how do I achieve the same thing in my case where the hostnames are in the git repository i.e., how do I specify that in the ansible.cfg file? 

Can you suggest the best approach here - saving the hostnames inside the Ansible server Vs. fetching that from a Git repository during the job run?

In my case

nik...@ansible.com

unread,
Dec 22, 2016, 12:26:30 PM12/22/16
to Ansible Project
There are couple of options here.

If its a host ini file, which is a static file and is not managed by any version control, you can use tower-manage to import the inventory to tower
http://docs.ansible.com/ansible-tower/latest/html/administration/tower-manage.html

There is also ability to add custom inventory scripts as dynamic inventory sources through the Tower UI.  You'll need to create a custom script that pulls the inventory data as json.

http://docs.ansible.com/ansible-tower/latest/html/administration/custom_inventory_script.html#custom-inventory-scripts

http://docs.ansible.com/ansible/developing_inventory.html#developing-dynamic-inventory-sources

Let me know if this helps.

Thanks,
Nikhil

Chethan S

unread,
Dec 22, 2016, 10:55:21 PM12/22/16
to Ansible Project
Thanks, Nikhil. The tower-manage inventory import did the trick. 

Marlon Guao

unread,
Nov 29, 2018, 5:50:04 AM11/29/18
to Ansible Project
I find it weird, using this approach that... intermittently, network will not be configured on your first entry(VM) in your inventory.
Reply all
Reply to author
Forward
0 new messages