Proxmox_vm_info: Failed To Retrieve QEMU VMs Information: 'template'
Summary
When attempting to use the proxmox_vm_info
module with a specific vmid
, users may encounter a rare and non-reproducible error:
Failed to retrieve QEMU VMs information: 'template'
This issue is likely caused by the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204.
Issue Type
Bug Report
Component Name
proxmox_vm_info
Ansible Version
$ ansible --version
ansible [core 2.16.6]
...
python version = 3.11.2 (main, Sep 14 2024, 03:00:30) [GCC 12.2.0] (/workspaces/.venv/bin/python)
jinja version = 3.1.6
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
Collection Version
----------------- -------
community.general 9.4.0
Configuration
$ ansible-config dump --only-changed
OS / Environment
No response
Steps to Reproduce
- name: Get vm configuration
community.general.proxmox_vm_info:
vmid: "{{ vmid }}"
config: current
register: proxmox_vm_info
Expected Results
TASK [deploy_vm : Get vm configuration] ************************ ok: [virtual_machine -> localhost] => "changed"
Actual Results
TASK [proxmox_deploy_vm : Get vm configuration] ************************
fatal: [virtual_machine -> localhost]: FAILED! => {"changed": false, "msg": "Failed to retrieve QEMU VMs information: 'template'"}
Possible Solution
The issue may be resolved by modifying the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204 to use desired_vm.get
instead of square brackets:
desired_vm["template"] = proxmox_to_ansible_bool(desired_vm.get("template", 0))
This change would replace the line with:
desired_vm["template"] = proxmox_to_ansible_bool(desired_vm.get("template", 0))
Impact
This change would likely resolve the issue and allow the proxmox_vm_info
module to function as expected.
Testing
To test this solution, users can modify the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204 to use desired_vm.get
instead of square brackets. Then, users can re-run the playbook and verify that the issue is resolved.
Conclusion
The proxmox_vm_info
module may encounter a rare and non-reproducible error when attempting to retrieve QEMU VMs information. This issue is likely caused by the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204. A possible solution is to modify the code to use desired_vm.get
instead of square brackets. This change would replace the line with:
desired_vm["template"] = proxmox_to_ansible_bool(desired_vm.get("template", 0))
Q: What is the issue with the proxmox_vm_info module?
A: The issue with the proxmox_vm_info module is that it may encounter a rare and non-reproducible error when attempting to retrieve QEMU VMs information. This error is typically displayed as:
Failed to retrieve QEMU VMs information: 'template'
Q: What is the cause of this issue?
A: The cause of this issue is likely due to the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204. This code uses square brackets to access the "template" key in the desired_vm
dictionary.
Q: What is the proposed solution to this issue?
A: The proposed solution to this issue is to modify the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204 to use desired_vm.get
instead of square brackets. This change would replace the line with:
desired_vm["template"] = proxmox_to_ansible_bool(desired_vm.get("template", 0))
Q: Why is this solution proposed?
A: This solution is proposed because it would allow the proxmox_vm_info
module to function as expected, even when the "template" key is not present in the desired_vm
dictionary. This would prevent the rare and non-reproducible error from occurring.
Q: How can I test this solution?
A: To test this solution, you can modify the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204 to use desired_vm.get
instead of square brackets. Then, you can re-run the playbook and verify that the issue is resolved.
Q: What are the benefits of this solution?
A: The benefits of this solution are that it would allow the proxmox_vm_info
module to function as expected, even in rare and non-reproducible scenarios. This would improve the reliability and stability of the module, and prevent the occurrence of the error.
Q: Are there any potential drawbacks to this solution?
A: There are no known potential drawbacks to this solution. However, it is always a good idea to thoroughly test any changes to code before implementing them in a production environment.
Q: How can I implement this solution in my Ansible playbook?
A: To implement this solution in your Ansible playbook, you can modify the code at https://github.com/ansible-collections/community.general/blob/stable-9/plugins/modules/proxmox_vm_info.py#L204 to use desired_vm.get
instead of square brackets. Then, you can re-run the playbook and verify that the issue is resolved.
Q: What are the system requirements for this solution?
A: The system requirements for this solution are that you must be running Ansible version 2.16.6 or later, and that you must have the community.general
collection installed.
Q: How can I get help if I encounter any issues with this solution?
A: If you encounter any issues with this solution, you can seek help from the Ansible community by posting a question on the Ansible forums or by reaching out to the Ansible support team.