vsphere_guest module and how to configure static IP

I want to use the vSphere_guest module to stand up a bunch of VMware VMs. But I don’t see a way to configure static IP. There are a few ways of making this happen, all involving the writing of custom code.

Is there really no way of doing this within the scope of the module? If not, any plans to add this functionality?

Jeff

sadly vmware/vcenter gives no direct way to do this, you either need to run a ‘boot script’ that does it or have the vmware guest tools installed.

Brian, I already have VMware tools installed, what options does that give me?

Jeff

Jeff,
You need to send the clone operation an customization spec in order to do guest customizations on a vSphere VM. This is not included in the vsphere_guest module.

From what I can tell from reading the roadmap (https://github.com/ansible/ansible/blob/devel/docsite/rst/roadmap/ROADMAP_2_2.rs) the ansible folks would like to add such features to vsphere_guest in the 2.2 release.

In the meantime, you can look at a module I wrote to accomplish this: https://github.com/whereismyjetpack/ansible_vcenter_module. It allows you to send specific guest customization parameters to the clone operation, the module is not ansibly (one of the first complaints I got), and requires pyvmomi instead of pysphere. I’ve been using this in production for a little over a year… feel free to contact me if you have any questions, and time permitting i’ll do my best to answer them. I’ve tested this code on vSphere 5.5 and 6.0.

Dann

Many thanks Dann, I’ll take a look. Yes, looks like the Ansible guys are onto it. I’m just about at the end of my own hand-crafted solution right now. So I’ll finish this off and take a look at your module afterwards.

Jeff

We do have plans to create a new guest module that also use pyvimomi, all modules should be using that library soon, also the inventory script, which is in devel right now.

Hey Dann, I’m drawing a blank on the final piece in my puzzle here, maybe you can help(?). I’ve registered the vmware_guest_facts in a var and just want to iterate through it, for each hw_eth0.ipaddresses[0] … e.g. this was my last (tortured) attempt:

  • name: copy new file into place
    delegate_to: “{{ item.[ {{ hw_eth0.ipaddresses[0] }} ] }}”
    template: src=xxxxxxx dest=/etc/xxxxxxxxxx
    with_nested:
  • “{{ vmware_guest_facts }}”
    become: yes

What’s the best way of doing this?

Jeff

while this approach probably works, i’m not sure how to help you here.

what i typically do is use the add_host module. something like this:

  • name: some playbook that does things

hosts: localhost

connection: local



tasks:

  • name: add host to in memory inventory

add_host: hostname=“new-vm{{some_var}}” ansible_ssh_host={{ vmware_guest_facts[‘guest_primary_ipaddress’]}} ansbile_ssh_port=22

  • name: some new playbook that does the work

hosts: "new-vm{{some_var}}

become: yes

tasks:

  • name: copy some file

template: src={{src}} dest={{dest}}

i typed this without checking it’s yaml syntax etc, but should give you a rough idea of the approach we use.

Dann

Thanks Dann.

Is there anything I can do to help? I brought this up in the devel list a few years ago, and was told that ansible didn't want to swap out the pysphere requirement, and at the time couldn't get pysphere to do what I wanted. I'd love to have some meaningful contribution back to the project

Dann, yes, after a lot of back and forth we decided to standardize on pyvimomi, all new modules have been using this library, the inventory script (which I wrote) and the vsphere_guest modules are the only outliers (they each use diff libs).

We currently have in devel a rewritten inventory script, so vsphere_guest is the last item on the list, we were planning on creating a new module(s) based on pyvimomi and deprecating vsphere_guest.

I was thinking of a vmware_vm or similar and possibly break out some of the functions in vsphere_guest to make 2 or 3 simpler modules (vmware_net, vmware_volume, etc), but there are no decisions made on this yet.