community.vmware icon indicating copy to clipboard operation
community.vmware copied to clipboard

vmware_portgroup, "hosts" or "cluster" required when logging into ESXi

Open springer268 opened this issue 11 months ago • 6 comments

Using an example with the same params as the first vmware_portgroup examples page

- name: Add Management Network VM Portgroup
  community.vmware.vmware_portgroup:
    hostname: "{{ esxi_hostname }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
    switch: "{{ vswitch_name }}"
    portgroup: "{{ portgroup_name }}"
    vlan_id: "{{ vlan_id }}"
  delegate_to: localhost

And logging into ESXi directly This returns

fatal: [localhost]: FAILED! => {"changed": false, "msg": "one of the following is required: cluster_name, hosts"}

This behavior makes sense for vCenter, but not for ESXi, and does not follow the example in the docs.

springer268 avatar Mar 15 '24 18:03 springer268

As a workaround (until fixed) you can add esxi_hostname: foobar, literally, as the name will be ignored when connecting to ESXi:

- name: Add Management Network VM Portgroup
  community.vmware.vmware_portgroup:
    hostname: "{{ esxi_hostname }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
    esxi_hostname: foobar
    switch: "{{ vswitch_name }}"
    portgroup: "{{ portgroup_name }}"
    vlan_id: "{{ vlan_id }}"
  delegate_to: localhost

Btw. esxi_hostname is an alias for hosts.

mbx64 avatar May 14 '24 11:05 mbx64

Yep, this is documentation issues.

Module community.vmware.vmware_portgroup need one of two required parameters - cluster_name or hosts. Even if you work with standalone esxi, you must specify this esxi in hosts.

- name: Add Management Network VM Portgroup
  community.vmware.vmware_portgroup:
    hostname: "{{ esxi_hostname }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
    hosts:
      - "{{ esxi_hostname }}"
    switch: "{{ vswitch_name }}"
    portgroup: "{{ portgroup_name }}"
    vlan_id: "{{ vlan_id }}"
  delegate_to: localhost

ihumster avatar May 14 '24 12:05 ihumster