vmware.vmware_rest.network_moid lookup – Look up MoID for vSphere network objects using vCenter REST API

Note

This lookup plugin is part of the vmware.vmware_rest collection (version 3.0.1).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install vmware.vmware_rest. You need further requirements to be able to use this lookup plugin, see Requirements for details.

To use it in a playbook, specify: vmware.vmware_rest.network_moid.

New in vmware.vmware_rest 2.1.0

Synopsis

  • Returns Managed Object Reference (MoID) of the vSphere network object contained in the specified path.

  • This lookup cannot distinguish between multiple networks with the same name defined in multiple switches as that is not supported by the vSphere REST API; network names must be unique within a given datacenter/folder path.

Requirements

The below requirements are needed on the local controller node that executes this lookup.

  • vSphere 7.0.3 or greater

  • python >= 3.6

  • aiohttp

Terms

Parameter

Comments

Terms

string / required

Path to query.

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('vmware.vmware_rest.network_moid', key1=value1, key2=value2, ...) and query('vmware.vmware_rest.network_moid', key1=value1, key2=value2, ...)

Parameter

Comments

vcenter_hostname

string / required

The hostname or IP address of the vSphere vCenter.

Configuration:

vcenter_password

string / required

The vSphere vCenter password.

Configuration:

vcenter_rest_log_file

string

You can use this optional parameter to set the location of a log file.

This file will be used to record the HTTP REST interactions.

The file will be stored on the host that runs the module.

Configuration:

vcenter_username

string / required

The vSphere vCenter username.

Configuration:

vcenter_validate_certs

boolean

Allows connection when SSL certificates are not valid. Set to false when certificates are not trusted.

Choices:

  • false

  • true ← (default)

Configuration:

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: lookup('vmware.vmware_rest.network_moid', term1, term2, key1=value1, key2=value2) and query('vmware.vmware_rest.network_moid', term1, term2, key1=value1, key2=value2)

Examples

# lookup sample
- name: set connection info
  ansible.builtin.set_fact:
    connection_args:
        vcenter_hostname: "vcenter.test"
        vcenter_username: "[email protected]"
        vcenter_password: "1234"

- name: lookup MoID of the object
  ansible.builtin.debug: msg="{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/test_network', **connection_args) }}"

- name: lookup MoID of the object inside the path
  ansible.builtin.debug: msg="{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/') }}"

Return Value

Key

Description

Return value

string

MoID of the vSphere network object

Returned: success

Sample: "network-1017"

Authors

  • Alina Buzachis (@alinabuzachis)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.