# Add interfaces during VM creation depends on conditionals

**URL:** <https://forum.ansible.com/t/add-interfaces-during-vm-creation-depends-on-conditionals/34206>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [November 18, 2020, 12:35pm UTC](https://forum.ansible.com/t/add-interfaces-during-vm-creation-depends-on-conditionals/34206 "2020-11-18T12:35:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hieronymus](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hieronymus/32/1624_2.png) [@hieronymus](https://forum.ansible.com/u/hieronymus)\
**Post date:** [November 18, 2020, 12:35pm UTC](https://forum.ansible.com/t/add-interfaces-during-vm-creation-depends-on-conditionals/34206/1 "2020-11-18T12:35:05Z")

</div>

Hi All,

On AWX I’m using the Survey to defined variables for creating a new VM Machine.  
There’re two cases of VM that I want to create, one with one interfaces and the other with 2 interfaces.  
I thought of inserting a conditional (when) for the creation of a second interface (because I cannot pass null values). With _host2int equal true or false_ But unfortunately, this conditionals didn’t works. I thought too, to add a vmware\_guest\_network to add a new interface but unfortunately this module doesn’t contain ip address and so on.

- name: Create VM  
vmware\_guest:  
annotation: " "  
hostname: “{{ vmware\_vcenter }}”  
username: “{{ vmware\_user }}”  
password: “{{ vmware\_password }}”  
validate\_certs: false  
datacenter: “{{ vmware\_datacenter }}”  
state: poweredoff  
folder: “{{ vmware\_folder }}”  
template: “{{ vmware\_template\_oss }}”  
name: “{{ vmware\_vmname }}”  
cluster: “{{ vmware\_cluster }}”  
datastore: “{{ vmware\_datastore }}”  
networks:
- name: “{{ vmware\_network }}”  
device\_type: “{{ vmware\_netdev }}”  
ip: “{{ vmware\_network\_ip }}”  
netmask: “{{ vmware\_network\_mask }}”  
gateway: “{{ vmware\_network\_gw }}”  
vlan: “{{ vmware\_network\_vlan }}”  
start\_connected: true
- name: “{{ vmware\_network2 }}”  
device\_type: “{{ vmware\_netdev }}”  
ip: “{{ vmware\_network\_ip2 }}”  
netmask: “{{ vmware\_network\_mask2 }}”  
vlan: “{{ vmware\_network\_vlan2 }}”  
start\_connected: “{{ host2int }}”  
when: host2int | bool  
customization:  
dns\_servers: “{{ vmware\_network\_dnsserver\_choice }}”  
domain: “{{ vmware\_network\_domain }}”  
dns\_suffix: “{{ vmware\_network\_dns\_suffix }}”  
hostname: “{{ vmware\_vmhostname }}”  
wait\_for\_ip\_address: true  
delegate\_to: localhost  
become: false

Someone has any idea how to resolve this configurations?  
Does something already exist for his situation?

Thank you in advance and best regards,  
H

---

<div class="post-metadata">

**Author:** ![Garrett\_Kelly](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@Garrett\_Kelly](https://forum.ansible.com/u/Garrett_Kelly)\
**Post date:** [November 20, 2020, 6:16pm UTC](https://forum.ansible.com/t/add-interfaces-during-vm-creation-depends-on-conditionals/34206/2 "2020-11-20T18:16:41Z")

</div>

Hey Hiero-nymo,

What about this.

Set host2int as “null” in your defaults.yml, and in the survey questions, set the default to be “false” for that variable. Go ahead and add the option to choose “true” in the dropdown.

Once that is done, go ahead and have a second tasks file included with something like this.

main.yml defaults file

# Set to NULL so that if role is run outside of AWX it can handle include yml

# ==\>

host2int: “”

main.yml tasks file

# ==\>

- name: include second nic  
include\_role:  
name: second\_nic.yml  
when:
- host2int == “true”
- host2int != “”

second\_nic.yml tasks file

# Of course it needs to have additional information in here to know what VM to apply this against, so you could pass the vmware\_vmname name as a var here from registered stdout. I didn’t add that here, but shouldn’t be much more code add

# ==\>

- name: “{{ vmware\_network2 }}”  
device\_type: “{{ vmware\_netdev }}”  
ip: “{{ vmware\_network\_ip2 }}”  
netmask: “{{ vmware\_network\_mask2 }}”  
vlan: “{{ vmware\_network\_vlan2 }}”  
start\_connected: “{{ host2int }}”  
when: host2int == “true”

---

<div class="post-metadata">

**Author:** ![hieronymus](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hieronymus/32/1624_2.png) [@hieronymus](https://forum.ansible.com/u/hieronymus)\
**Post date:** [November 25, 2020, 2:28pm UTC](https://forum.ansible.com/t/add-interfaces-during-vm-creation-depends-on-conditionals/34206/3 "2020-11-25T14:28:00Z")

</div>

Hi,

Thanks for your reply and help.  
Very good idea… I followed your advice and it works…  
However, I cannot used vmware\_guest but vmware\_guest\_network and there is no possibility to configure IP, etc… but I have found another way…

Best regards,  
Hiero-nymus
