How to collect information about your environment
Introduction
This section shows you how to utilize Ansible to collect information about your environment. This information is useful for the other tutorials.
Scenario requirements
In this scenario we’ve got a vCenter with an ESXi host.
Our environment is pre-initialized with the following elements:
- A datacenter called
my_dc
- A cluster called
my_cluser
- A cluster called
my_cluser
- An ESXi host called
esxi1
is in the cluster - Two datastores on the ESXi:
rw_datastore
andro_datastore
- A dvswitch based guest network
Finally, we use the environment variables to authenticate ourselves as explained in How to configure the vmware_rest collection.
How to collect information
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.
Datacenter
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
Result
As expected, the value
key of the output is a list.
{ "value": [ { "name": "my_dc", "datacenter": "datacenter-1630" } ], "changed": false }
Cluster
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
Result
{ "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
Result
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 }
Datastore
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
Result
{ "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 }
Folder
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
Result
{ "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
Result
{ "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