community.vmware.vmware_host_inventory – VMware ESXi hostsystem inventory source

Note

This plugin is part of the community.vmware collection (version 1.17.0).

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 community.vmware.

To use it in a playbook, specify: community.vmware.vmware_host_inventory.

New in version 1.11.0: of community.vmware

Synopsis

  • Get VMware ESXi hostsystem as inventory hosts from VMware environment.

  • Uses any file which ends with vmware.yml, vmware.yaml, vmware_host_inventory.yml, or vmware_host_inventory.yaml as a YAML configuration file.

Requirements

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

  • Python >= 2.7

  • PyVmomi

  • requests >= 2.3

  • vSphere Automation SDK - For tag feature

Parameters

Parameter

Comments

cache

boolean

Toggle to enable/disable the caching of the inventory’s source data, requires a cache plugin setup to work.

Choices:

  • no ← (default)

  • yes

Configuration:

  • INI entry:

    [inventory]
    cache = no
    
  • Environment variable: ANSIBLE_INVENTORY_CACHE

cache_connection

string

Cache connection data or path, read cache plugin documentation for specifics.

Configuration:

  • INI entries:

    [defaults]
    fact_caching_connection = None
    
    [inventory]
    cache_connection = None
    
  • Environment variable: ANSIBLE_CACHE_PLUGIN_CONNECTION

  • Environment variable: ANSIBLE_INVENTORY_CACHE_CONNECTION

cache_plugin

string

Cache plugin to use for the inventory’s source data.

Default: “memory”

Configuration:

  • INI entries:

    [defaults]
    fact_caching = memory
    
    [inventory]
    cache_plugin = memory
    
  • Environment variable: ANSIBLE_CACHE_PLUGIN

  • Environment variable: ANSIBLE_INVENTORY_CACHE_PLUGIN

cache_prefix

string

Prefix to use for cache plugin files/tables

Default: “ansible_inventory_”

Configuration:

  • INI entries:

    [default]
    fact_caching_prefix = ansible_inventory_
    
    [inventory]
    cache_prefix = ansible_inventory_
    
  • Environment variable: ANSIBLE_CACHE_PLUGIN_PREFIX

  • Environment variable: ANSIBLE_INVENTORY_CACHE_PLUGIN_PREFIX

cache_timeout

integer

Cache duration in seconds

Default: 3600

Configuration:

  • INI entries:

    [defaults]
    fact_caching_timeout = 3600
    
    [inventory]
    cache_timeout = 3600
    
  • Environment variable: ANSIBLE_CACHE_PLUGIN_TIMEOUT

  • Environment variable: ANSIBLE_INVENTORY_CACHE_TIMEOUT

compose

dictionary

Create vars from jinja2 expressions.

Default: {}

filters

list / elements=string

This option allows client-side filtering hosts with jinja templating.

When server-side filtering is introduced, it should be preferred over this.

Default: []

groups

dictionary

Add hosts to group based on Jinja2 conditionals.

Default: {}

hostname

string / required

Name of vCenter or ESXi server.

Configuration:

  • Environment variable: VMWARE_HOST

  • Environment variable: VMWARE_SERVER

hostnames

list / elements=string

A list of templates in order of precedence to compose inventory_hostname.

Ignores template if resulted in an empty string or None value.

You can use property specified in properties as variables in the template.

Default: [“name”]

keyed_groups

list / elements=string

Add hosts to group based on the values of a variable.

Default: [{“key”: “summary.runtime.powerState”, “separator”: “”}]

leading_separator

boolean

added in 2.11 of ansible.builtin

Use in conjunction with keyed_groups.

By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.

This is because the default prefix is “” and the default separator is “_”.

Set this option to False to omit the leading underscore (or other separator) if no prefix is given.

If the group name is derived from a mapping the separator is still used to concatenate the items.

To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.

Choices:

  • no

  • yes ← (default)

password

string / required

Password of vSphere user.

Accepts vault encrypted variable.

Configuration:

  • Environment variable: VMWARE_PASSWORD

port

integer

Port number used to connect to vCenter or ESXi Server.

Default: 443

Configuration:

  • Environment variable: VMWARE_PORT

properties

list / elements=string

Specify the list of VMware schema properties associated with the ESXi hostsystem.

These properties will be populated in hostvars of the given ESXi hostsystem.

Each value in the list can be a path to a specific property in hostsystem object or a path to a collection of hostsystem objects.

summary.runtime.powerState are required if keyed_groups is set to default.

Please make sure that all the properties that are used in other parameters are included in this options.

In addition to ESXi hostsystem’s properties, the following are special values

Use customValue to populate ESXi hostsystem’s custom attributes. customValue is only supported by vCenter and not by ESXi.

Use all to populate all the properties of the virtual machine. The value all is time consuming operation, do not use unless required absolutely.

Default: [“name”, “customValue”, “summary.runtime.powerState”]

proxy_host

string

added in 1.12.0 of community.vmware

Address of a proxy that will receive all HTTPS requests and relay them.

The format is a hostname or a IP.

This feature depends on a version of pyvmomi>=v6.7.1.2018.12.

Configuration:

  • Environment variable: VMWARE_PROXY_HOST

proxy_port

integer

added in 1.12.0 of community.vmware

Port of the HTTP proxy that will receive all HTTPS requests and relay them.

Configuration:

  • Environment variable: VMWARE_PROXY_PORT

resources

list / elements=string

A list of resources to limit search scope.

Each resource item is represented by exactly one 'vim_type_snake_case:list of resource names pair and optional nested resources

Key name is based on snake case of a vim type name; e.g host_system correspond to vim.HostSystem

Default: []

strict

boolean

If yes make invalid entries a fatal error, otherwise skip and continue.

Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.

Choices:

  • no ← (default)

  • yes

use_extra_vars

boolean

added in 2.11 of ansible.builtin

Merge extra vars into the available variables for composition (highest precedence).

Choices:

  • no ← (default)

  • yes

Configuration:

  • INI entry:

    [inventory_plugins]
    use_extra_vars = no
    
  • Environment variable: ANSIBLE_INVENTORY_USE_EXTRA_VARS

username

string / required

Name of vSphere user.

Accepts vault encrypted variable.

Configuration:

  • Environment variable: VMWARE_USER

  • Environment variable: VMWARE_USERNAME

validate_certs

boolean

Allows connection when SSL certificates are not valid.

Set to false when certificates are not trusted.

Choices:

  • no

  • yes ← (default)

Configuration:

  • Environment variable: VMWARE_VALIDATE_CERTS

with_nested_properties

boolean

This option transform flatten properties name to nested dictionary.

Choices:

  • no

  • yes ← (default)

with_path

boolean

Include ESXi hostsystem’s path.

Set this option to a string value to replace root name from ‘Datacenters’.

Choices:

  • no ← (default)

  • yes

with_sanitized_property_name

boolean

This option allows property name sanitization to create safe property names for use in Ansible.

Also, transforms property name to snake case.

Choices:

  • no ← (default)

  • yes

with_tags

boolean

Include tags and associated hosts.

Requires ‘vSphere Automation SDK’ library to be installed on the given controller machine.

Please refer following URLs for installation steps

https://code.vmware.com/web/sdk/7.0/vsphere-automation-python

Choices:

  • no ← (default)

  • yes

Examples

# Sample configuration file for VMware Host dynamic inventory
    plugin: community.vmware.vmware_host_inventory
    strict: False
    hostname: 10.65.223.31
    username: [email protected]
    password: Esxi@123$%
    validate_certs: False
    with_tags: True

# Using compose
    plugin: community.vmware.vmware_host_inventory
    hostname: 10.65.223.31
    username: [email protected]
    password: Esxi@123$%
    validate_certs: False
    properties:
    - name
    - summary
    - config.lockdownMode
    compose:
        ansible_user: "'root'"
        ansible_connection: "'ssh'"

Authors

  • Abhijeet Kasurde (@Akasurde)