Add interfaces during VM creation depends on conditionals

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

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”

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