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_kvm: Cloning template to create new VM fails #7017

Closed jhofmueller closed 1 year ago

jhofmueller commented 1 year ago

Summary

When I try to clone a new VM from an existing template named "ubuntu" I get the error "VM with name = ubuntu does not exist in cluster". This is the task:

- name: Clone VM
  community.general.proxmox_kvm:
    api_host: HOST
    api_user: "{{ proxmox_api_user }}"
    api_token_id: "{{ proxmox_api_token_id }}"
    api_token_secret: "{{ proxmox_api_token_secret }}"
    clone: ubuntu
    name: zavala
    node: NODE
    storage: STORAGE
    format: qcow2
    timeout: 500

Issue Type

Bug Report

Component Name

proxmox_kvm

Ansible Version

$ ansible --version
ansible [core 2.12.8]
  config file = /home/jogi/git/dcim/netbox-dev/ansible.cfg
  configured module search path = ['/home/jogi/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/jogi/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0]
  jinja version = 3.0.3
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /home/USER/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 7.1.0  

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

Configuration

$ ansible-config dump --only-changed

OS / Environment

Ubuntu 22.04.2

Steps to Reproduce


- name: Clone VM
  community.general.proxmox_kvm:
    api_host: HOST
    api_user: "{{ proxmox_api_user }}"
    api_token_id: "{{ proxmox_api_token_id }}"
    api_token_secret: "{{ proxmox_api_token_secret }}"
    clone: ubuntu
    name: zavala
    node: NODE
    storage: STORAGE
    format: qcow2
    timeout: 500

Expected Results

I expected a new VM cloned from the specified template.

Actual Results

TASK [proxmox_vm : Clone VM] ****************************************************************************************************************************************************************
fatal: [PROXMOX]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "msg": "VM with name = ubuntu does not exist in cluster"}

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

Code of Conduct

ansibullbot commented 1 year 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 1 year ago

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

UnderGreen commented 1 year ago

The only explanation from the code I see: you have no VM with the name ubuntu in a cluster. The function which collects vmid for that name returned 0 results and that led to fail.

jhofmueller commented 1 year ago

I'm terribly sorry but that doesn't work for me. I can confirm that the VM in question exists (it's a template, but that should not matter, right?) but the same error keeps popping up.

The only thing that comes to my mind is that our cluster has only one node. But that should not be a problem, right?

UnderGreen commented 1 year ago

With the current main branch code I can clone the VM and don't see any problem.

TASK [Clone new VM] ****************************************************************************************************************************************
changed: [localhost] => {"changed": true, "msg": "VM pxe-cloned.home.arpa with newid 104 cloned from vm with vmid 100", "vmid": "104"}

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

There could be an explanation for your case. Invisible space character in the name or any UTF character which looks like a Latin letter. You can use proxmox_vm_info module to get all VMs information and copy the exact name from the console output.

jhofmueller commented 1 year ago

That was not the problem either. I did some more debugging and found the following:

I have no explanation for this behavior and will sleep over it one more night. Thanks for your support so far!

UnderGreen commented 1 year ago
$ ansible-galaxy collection list community.general
# /home/USER/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 7.1.0  

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

Just to rule out that it is not a problem with multiple collections used I would recommend next steps to try:

  1. Create a new Python virtual environment and activate it.
  2. Install proxmoxer and ansible-core Python modules

I think after that ansible-core installation must use your 7.1.0 community.general collection.

jhofmueller commented 1 year ago

That is not it either. Furthermore, I had to upgrade to community.general 7.2.1 in order to be able to use the proxmox_vm_info module. So I can assure that the most recent version of community.general is being used.

Just to clarify: proxmoxeris installed on the proxmox node, not on my workstation that runs the playbook.

UnderGreen commented 1 year ago

proxmoxer library should be installed there, where you set your hosts: in a playbook. If you don't set, then localhost is assumed, which is your workstation in that case.

jhofmueller commented 1 year ago

I am still at a loss here :cry: I can create a VM using proxmox_kvm. I cannot get a list of the VMs on the node using proxmox_vm_info. Hence I can also not clone an existing VM.

No clue what is wrong here. Since creating VMs works the basic setup including permissions must be correct, right? I am using a token linked to the root user and no privilege separation for these tests.

ChristopherJHart commented 1 year ago

I encountered this same issue with community.general collection 7.5.0, ansible-core 2.15.5, Python 3.10.12. I only encountered this issue when using API keys - using just api_user and api_password works fine, but api_token_id and api_token_secret does not work.

jhofmueller commented 1 year ago

Thanks for your message! I tried it again today and low and behold, it worked as expected. I still have the same ansible environment but my proxmox cluster has been upgrade multiple times and run's the most recent software. I have no clue what went wrong or where the error was hidden.