ansible-collections/community.vmware

Unable to gather information about snapshots for non-existing VM

ick0 opened this issue · 2 comments

ick0 commented
SUMMARY

We have two identical ansible control nodes, one of them running RedHAt 8.9, ansible 2.9 and we have upgraded the other node to RedHat 9.4 and ansible 2.14. On the latter we have installed community.vmware 3.11.3 and pyvmomi 7.0.3 but cannot get the vmware_guest_snapshot_info to work

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_guest_snapshot_info
vmware_guest_snapshot

ANSIBLE VERSION
ansible [core 2.14.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/bionix/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/bionix/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Jan 24 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/bionix/.local/lib/python3.9/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 3.9.0
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 20
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/home/****/infra/ansible/inventory/all_hosts.ini']
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /var/log/ansible.log
DEFAULT_REMOTE_USER(/etc/ansible/ansible.cfg) = ******
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = ['/home/*****/infra/ansible/roles']
DEFAULT_VAULT_PASSWORD_FILE(/etc/ansible/ansible.cfg) = /home/*****/.ansible/.secret
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

RHEL9.4
kernel 5.14.0-427.13.1.el9_4.x86_64

STEPS TO REPRODUCE

I am running the below playbook with this command ansible-playbook test.yml -vvv and it fails with "Unable to manage snapshots for non-existing VM RHEL9TEST"

- hosts: localhost
  gather_facts: False
  collections:
    - community.vmware
  vars_files:
    - esxi_vars.yml

  tasks:
  - name: Get folder path for VMware virtual machine
    vmware_guest_find:
      validate_certs: false
      hostname: "{{ esxi_host }}"
      username: "{{ AD_user }}"
      password: "{{ AD_pass }}"
      name: "{{ host_to_check }}"
    register: folder_details
    tags: find_snaps

  - name: Gather info from standalone ESXi server having datacenter
    vmware_guest_info:
      hostname: "{{ esxi_host }}"
      username: "{{ AD_user }}"
      password: "{{ AD_pass }}"
      datacenter: "{{ datacenter }}"
      name: "{{ host_to_check }}"
      validate_certs: false
      folder: folder_details.stdout
EXPECTED RESULTS

I am expecting the playbook to gather information about the VM. The same code works as expected on the other node running RedHat 8.9 and ansible 2.9

ACTUAL RESULTS
ansible-playbook [core 2.14.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/*****/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/*****/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.18 (main, Jan 24 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/*****/infra/ansible/inventory/all_hosts.ini as it did not pass its verify_file() method
script declined parsing /home/*****/infra/ansible/inventory/all_hosts.ini as it did not pass its verify_file() method
auto declined parsing /home/*****/infra/ansible/inventory/all_hosts.ini as it did not pass its verify_file() method
yaml declined parsing /home/*****/infra/ansible/inventory/all_hosts.ini as it did not pass its verify_file() method
Parsed /home/*****/infra/ansible/inventory/all_hosts.ini inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yml **************************************************************************************************************************************************************************************************************************
1 plays in test.yml
Read vars_file 'esxi_vars.yml'
Read vars_file 'esxi_vars.yml'
Read vars_file 'esxi_vars.yml'

PLAY [localhost] ****************************************************************************************************************************************************************************************************************************
Read vars_file 'esxi_vars.yml'
Read vars_file 'esxi_vars.yml'
Read vars_file 'esxi_vars.yml'

TASK [Get folder path for VMware virtual machine] *******************************************************************************************************************************************************************************************
task path: /home/*****/infra/ansible/plays/test.yml:9
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: *****
<127.0.0.1> EXEC /bin/sh -c 'echo ~***** && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/*****/.ansible/tmp `"&& mkdir "` echo /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397 `" && echo ansible-tmp-1715857260.3922727-124224-137916737540397="` echo /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397 `" ) && sleep 0'
Using module file /home/*****/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vmware_guest_find.py
<127.0.0.1> PUT /home/*****/.ansible/tmp/ansible-local-1242204zxmwg2x/tmpe87ge58z TO /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397/AnsiballZ_vmware_guest_find.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397/ /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397/AnsiballZ_vmware_guest_find.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397/AnsiballZ_vmware_guest_find.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/*****/.ansible/tmp/ansible-tmp-1715857260.3922727-124224-137916737540397/ > /dev/null 2>&1 && sleep 0'
ok: [localhost] => {
    "changed": false,
    "folders": [
        "************"
    ],
    "invocation": {
        "module_args": {
            "hostname": "*******",
            "name": "*******",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "use_instance_uuid": false,
            "username": "*******",
            "uuid": null,
            "validate_certs": false
        }
    }
}
Read vars_file 'esxi_vars.yml'

TASK [Gather info from standalone ESXi server having datacenter] ****************************************************************************************************************************************************************************
task path: /home/*****/infra/ansible/plays/test.yml:19
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: *****
<127.0.0.1> EXEC /bin/sh -c 'echo ~***** && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/*****/.ansible/tmp `"&& mkdir "` echo /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269 `" && echo ansible-tmp-1715857262.0869331-124252-217775127795269="` echo /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269 `" ) && sleep 0'
Using module file /home/*****/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vmware_guest_info.py
<127.0.0.1> PUT /home/*****/.ansible/tmp/ansible-local-1242204zxmwg2x/tmpeigjxm3z TO /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269/AnsiballZ_vmware_guest_info.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269/ /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269/AnsiballZ_vmware_guest_info.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269/AnsiballZ_vmware_guest_info.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/*****/.ansible/tmp/ansible-tmp-1715857262.0869331-124252-217775127795269/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "*******",
            "folder": "folder_details.stdout",
            "hostname": "*******",
            "moid": null,
            "name": "*******",
            "name_match": "first",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "properties": null,
            "proxy_host": null,
            "proxy_port": null,
            "schema": "summary",
            "tag_details": false,
            "tags": false,
            "use_instance_uuid": false,
            "username": "*******",
            "uuid": null,
            "validate_certs": false
        }
    },
    "msg": "Unable to gather information for non-existing VM ******"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

You use folder_details.stdout variable for parameter folder in module vmware_guest_info. Make sure that the contents of folder_details.stdout match the required path format for the folder parameter.

ick0 commented

Thanks` a lot, Alexander, that was the issue... In this newer version of the vmware modules, the get folder module returns a list instead of string like the old one and I had to adjust my playbook in order to work. But it works!, thank you again