ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
827 stars 1.52k forks source link

proxmox: state=template is not idempotent (for LXCs) #8811

Open fdcastel opened 2 months ago

fdcastel commented 2 months ago

Summary

Setting state:template on a LXC that is already a template fails with:

"msg": "conversion of VM 901 to template failed with exception: 500 Internal Server Error: you can't convert a template to a 
template"

This is exactly the same problem fixed in #7791, but now for LXCs (#7791 fixed it only for VMs).

Issue Type

Bug Report

Component Name

proxmox

Ansible Version

$ ansible --version

ansible [core 2.16.10]
  config file = /opt/araponga-ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.6.4

Configuration

$ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/opt/araponga-ansible/ansible.cfg) = True
CONFIG_FILE() = /opt/araponga-ansible/ansible.cfg
DEFAULT_FORKS(/opt/araponga-ansible/ansible.cfg) = 12
DEFAULT_STRATEGY(/opt/araponga-ansible/ansible.cfg) = free

OS / Environment

Ubuntu 24.04 LTS Promox VE 8.2.4

Steps to Reproduce

Expected Results

Skip (do not run) the task since it is already in the declared state.

Actual Results


fatal: [template-docker -> localhost({{inventory_hostname_short}}.{{domain_name}})]: FAILED! => {"changed": false, "msg": "conversion of VM 901 to template failed with exception: 500 Internal Server Error: you can't convert a template to a template", "vmid": 901}

Code of Conduct

ansibullbot commented 2 months ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 2 months ago

cc @Ajpantuso @Thulium-Drake @UnderGreen @joshainglis @karmab @krauthosting click here for bot help

fdcastel commented 2 months ago

Workaround (for now)

        - name: Retrieve information about specific VM by ID
          community.general.proxmox_vm_info:
            vmid: "{{ lxc_id }}"
            type: lxc
          register: vm_info_result

        - name: "LXC container: convert to template"
          community.general.proxmox:
            vmid: "{{ lxc_id }}"
            state: template
            node: "{{ pve_host }}"
            api_host: "{{ proxmox.api_host }}"
            api_user: "{{ proxmox.api_user }}"
            api_password: "{{ proxmox.api_password }}"
          when: not vm_info_result.proxmox_vms[0].template