This section shows you how to utilize Ansible to collect information about your environment. This information is useful for the other tutorials.
In this scenario we’ve got a vCenter with an ESXi host.
Our environment is pre-initialized with the following elements:
my_dc
my_cluser
my_cluser
esxi1
is in the clusterrw_datastore
and ro_datastore
Finally, we use the environment variables to authenticate ourselves as explained in How to configure the vmware_rest collection.
In these examples, we use the vcenter_*_info
module to collect information about the associated resources.
All these modules return a value
key. Depending on the context, this value
key will be either a list or a dictionary.
Here we use the vcenter_datacenter_info
module to list all the datacenters:
- name: collect a list of the datacenters vmware.vmware_rest.vcenter_datacenter_info: register: my_datacenters
As expected, the value
key of the output is a list.
{ "value": [ { "name": "my_dc", "datacenter": "datacenter-1630" } ], "changed": false }
Here we do the same with vcenter_cluster_info
:
- name: Build a list of all the clusters vmware.vmware_rest.vcenter_cluster_info: register: all_the_clusters
{ "value": [ { "drs_enabled": false, "cluster": "domain-c1636", "name": "my_cluster", "ha_enabled": false } ], "changed": false }
And we can also fetch the details about a specific cluster, with the cluster
parameter:
- name: Retrieve details about the first cluster vmware.vmware_rest.vcenter_cluster_info: cluster: "{{ all_the_clusters.value[0].cluster }}" register: my_cluster_info
And the value
key of the output is this time a dictionary.
{ "value": { "name": "my_cluster", "resource_pool": "resgroup-1637" }, "id": "domain-c1636", "changed": false }
Here we use vcenter_datastore_info
to get a list of all the datastores:
- name: Retrieve a list of all the datastores vmware.vmware_rest.vcenter_datastore_info: register: my_datastores
{ "value": [ { "datastore": "datastore-1644", "name": "local", "type": "VMFS", "free_space": 13523484672, "capacity": 15032385536 }, { "datastore": "datastore-1645", "name": "ro_datastore", "type": "NFS", "free_space": 24638349312, "capacity": 26831990784 }, { "datastore": "datastore-1646", "name": "rw_datastore", "type": "NFS", "free_space": 24638349312, "capacity": 26831990784 } ], "changed": false }
And here again, you use the vcenter_folder_info
module to retrieve a list of all the folders.
- name: Build a list of all the folders vmware.vmware_rest.vcenter_folder_info: register: my_folders
{ "value": [ { "folder": "group-d1", "name": "Datacenters", "type": "DATACENTER" } ], "changed": false }
Most of the time, you will just want one type of folder. In this case we can use filters to reduce the amount to collect. Most of the _info
modules come with similar filters.
- name: Build a list of all the folders with the type VIRTUAL_MACHINE and called vm vmware.vmware_rest.vcenter_folder_info: filter_type: VIRTUAL_MACHINE filter_names: - vm register: my_folders
{ "value": [ { "folder": "group-v1631", "name": "vm", "type": "VIRTUAL_MACHINE" } ], "changed": false }
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/scenario_guides/vmware_rest_scenarios/collect_information.html