I'm new at this too. I just got my first ever playbook to run the other day.
So this is what my playbook looks like. Note that I keep my credentials for vCenter in a vault, which is NOT required.
[glporter@montara 29Aug1743Z ansible]$
rToShowSnapshots.ymlAug1743Z ansible]$cat playbooks/vmware/testPlaybookForVcenterToShowSnapshots.yml
---
- hosts: 127.0.0.1
#
gather_facts: false
connection: local
# Do some random command vCenter task....
tasks:
# On the command line use --extra-vars="my_vault=/path/to/vault"
- include_vars: "{{ my_vault }}"
no_log: true
- name: Gather facts about the virtual machine's snapshots in given vCenter
vmware_guest_snapshot_facts:
datacenter: smx
hostname: redacted
uuid: 420b20a6-ab00-fe60-3a75-b9ed3a666f72
password: "{{ vcenter_morro_mgmt_smx_password }}"
username: "{{ vcenter_morro_mgmt_smx_username }}"
validate_certs: no
delegate_to: localhost
register: facts
no_log: true
- name: Display all facts known for a VM
debug:
msg: "{{ item }}"
with_items:
[glporter@montara 29Aug1752Z ansible]$ ansible-playbook -i inventories/smx/hosts playbooks/vmware/testPlaybookForVcenterToShowSnapshots.yml --ask-vault-pass --extra-vars "my_vault=/home/glporter/git/st-utilities/ansible/vault/smx_vault.yml" -v
Using /home/glporter/git/st-utilities/ansible/ansible.cfg as config file
Vault password:
PLAY [127.0.0.1] **********************************************************************************************
TASK [include_vars] *******************************************************************************************
ok: [127.0.0.1] => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
TASK [Gather facts about the virtual machine's snapshots in given vCenter] ************************************
ok: [127.0.0.1 -> localhost] => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}
TASK [Display all facts known for a VM] ***********************************************************************
ok: [127.0.0.1] => (item={'failed': False, u'changed': False, u'guest_snapshots': {u'current_snapshot': {u'id': 215, u'state': u'poweredOn', u'creation_time': u'2018-08-20T18:43:48.086085+00:00', u'description': u'bar', u'name': u'test snap 2'}, u'snapshots': [{u'state': u'poweredOn', u'creation_time': u'2018-08-20T14:17:41.428299+00:00', u'description': u'before install of pyvmomi', u'name': u'2018-08-20', u'id': 213}, {u'state': u'poweredOn', u'creation_time': u'2018-08-20T18:42:59.533428+00:00', u'description': u'foo', u'name': u'test snap 1', u'id': 214}, {u'state': u'poweredOn', u'creation_time': u'2018-08-20T18:43:48.086085+00:00', u'description': u'bar', u'name': u'test snap 2', u'id': 215}]}}) => {
"msg": {
"changed": false,
"failed": false,
"guest_snapshots": {
"current_snapshot": {
"creation_time": "2018-08-20T18:43:48.086085+00:00",
"description": "bar",
"id": 215,
"name": "test snap 2",
"state": "poweredOn"
},
"snapshots": [
{
"creation_time": "2018-08-20T14:17:41.428299+00:00",
"description": "before install of pyvmomi",
"id": 213,
"name": "2018-08-20",
"state": "poweredOn"
},
{
"creation_time": "2018-08-20T18:42:59.533428+00:00",
"description": "foo",
"id": 214,
"name": "test snap 1",
"state": "poweredOn"
},
{
"creation_time": "2018-08-20T18:43:48.086085+00:00",
"description": "bar",
"id": 215,
"name": "test snap 2",
"state": "poweredOn"
}
]
}
}
}
PLAY RECAP ****************************************************************************************************
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0