# vsphere\_guest module and how to configure static IP

**URL:** <https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [June 13, 2016, 6:55pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758 "2016-06-13T18:55:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [June 13, 2016, 6:55pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/1 "2016-06-13T18:55:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 15, 2016, 4:06pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/2 "2016-06-15T16:06:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [June 15, 2016, 8:03pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/3 "2016-06-15T20:03:10Z")

</div>

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

Jeff

---

<div class="post-metadata">

**Author:** ![Dann\_Bohn](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dann\_Bohn](https://forum.ansible.com/u/Dann_Bohn)\
**Post date:** [June 16, 2016, 2:01am UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/4 "2016-06-16T02:01:34Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [June 16, 2016, 6:52pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/5 "2016-06-16T18:52:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 16, 2016, 8:04pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/6 "2016-06-16T20:04:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [June 16, 2016, 10:34pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/7 "2016-06-16T22:34:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dann\_Bohn](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dann\_Bohn](https://forum.ansible.com/u/Dann_Bohn)\
**Post date:** [June 16, 2016, 10:54pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/8 "2016-06-16T22:54:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jeff\_Richards](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@Jeff\_Richards](https://forum.ansible.com/u/Jeff_Richards)\
**Post date:** [June 16, 2016, 11:07pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/9 "2016-06-16T23:07:38Z")

</div>

Thanks Dann.

---

<div class="post-metadata">

**Author:** ![Dann\_Bohn](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dann\_Bohn](https://forum.ansible.com/u/Dann_Bohn)\
**Post date:** [June 17, 2016, 4:47pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/10 "2016-06-17T16:47:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 17, 2016, 4:55pm UTC](https://forum.ansible.com/t/vsphere-guest-module-and-how-to-configure-static-ip/21758/11 "2016-06-17T16:55:07Z")

</div>

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.
