Proxmox 8 lxc containers and ansible community.general.proxmox support

dsexton18

Member
Jul 3, 2023
41
1
8
Does any know if community.general.proxmox module supports or works properly with proxmox 8?

Management of instances in Proxmox VE clusterI wrote a basic role based of one of the examples. But get
msg": "Creation of lxc VM 901 failed with exception: 400 Bad Request: Parameter verification failed.",
"vmid": 901

Any help or suggestion is appreciated.

cat roles/create-container/tasks/main.yml
Code:
- name: Create new container automatically selecting the next available vmid.
  community.general.proxmox:
    node: "{{ pve_node }}"
    api_user: 'lxc1@pve'
    api_password: 'password_here'
    api_host: 'pve2'
    vmid: 901
    password: 'password'
    hostname: 'hoste1'
    ostemplate: 'vm_data2:vztmpl/rockylinux-9-default_20221109_amd64.tar.xz'

cat roles/create-container/vars/main.yml

ansible-playbook -i inventory create_container.yml -vvv
Code:
The full traceback is:
  File "/tmp/ansible_community.general.proxmox_payload_z6akafqp/ansible_community.general.proxmox_payload.zip/ansible_collections/community/general/plugins/modules/proxmox.py", line 880, in main
  File "/tmp/ansible_community.general.proxmox_payload_z6akafqp/ansible_community.general.proxmox_payload.zip/ansible_collections/community/general/plugins/modules/proxmox.py", line 661, in create_instance
  File "/usr/lib/python3/dist-packages/proxmoxer/core.py", line 135, in create
    return self.post(*args, **data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proxmoxer/core.py", line 126, in post
    return self(args)._request("POST", data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/proxmoxer/core.py", line 105, in _request
    raise ResourceException(
fatal: [pve2.foo.lan]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "api_host": "pve2",
            "api_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "api_token_id": null,
            "api_token_secret": null,
            "api_user": "lxc1@pve",
            "clone": null,
            "clone_type": "opportunistic",
            "cores": null,
            "cpus": null,
            "cpuunits": null,
            "description": null,
            "disk": null,
            "features": null,
            "force": false,
            "hookscript": null,
            "hostname": "host1",
            "ip_address": null,
            "memory": null,
            "mounts": null,
            "nameserver": null,
            "netif": null,
            "node": "pve2",
            "onboot": null,
            "ostemplate": "vm_data2:vztmpl/rockylinux-9-default_20221109_amd64.tar.xz",
            "ostype": "auto",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "pool": null,
            "proxmox_default_behavior": "no_defaults",
            "pubkey": null,
            "purge": false,
            "searchdomain": null,
            "state": "present",
            "storage": "local",
            "swap": null,
            "tags": null,
            "timeout": 30,
            "timezone": null,
            "unprivileged": true,
            "update": false,
            "validate_certs": false,
            "vmid": 901
        }
    },
    "msg": "Creation of lxc VM 901 failed with exception: 400 Bad Request: Parameter verification failed.",
    "vmid": 901
}
YAML:
---
# vars file for roles/create-container
pve_node: pve2
 
Last edited:
I found an ansible role that someone created on github that was pretty useful. I ended up having to put in a pull request to change some of the community.general.proxmox documentation for disk size stuff cause of some errors after trying to use it.

https://github.com/UdelaRInterior/ansible-role-proxmox-create-lxc

Recommend you check it out. I'm trying to use it to create a template lxc that I can then use to deploy the rest of my infrastructure.
 
Hey @dsexton18 , not sure if you've managed something already but I was facing the same issue.

I took a look at the role @xhk416x linked above, and while it did help me improve my setup a bit, that's basically just a wrapper around the `community.general.proxmox` role.

In the end, I've managed to figure my issue out by trying the API directly. You can check the API wiki page on how to authenticate and perform basic queries (there's even a bare-bones create lxc example over there). Replacing that with the parameters I was trying to use with ansible gave me a better error message - it turned out the mac address I was trying to use was invalid for some reason.
 
@dsexton18 @titolins Did either of you get this working by using the community.general.proxmox role by itself?
I'm having exactly the same issue and would prefer to fix this without making direct API calls which is the reason I'm using ansible in the first place
 
I'm not sure if this is what fixed it for me as I tried a few things, but I had installed proxmoxer on my host with apt install python3-proxmoxer which installed version 1.2.0-2. Using pipx also didn't seem to install version 2 so I uninstalled all versions of Proxmoxer on the host and just grabbed it from github and installed it locally with the code below.

Bash:
wget https://github.com/proxmoxer/proxmoxer
tar -xf 2.0.1.tar.gz
cd proxmoxer-2.0.1
python3 setup.py install

Hopefully this helps others.

P.S. I also confirmed I could create LXC's directly with the API from my ansible controller and directly on the host with PVESH to rule out issues with connectivity or the API itself.
 
Last edited:
On a fresh proxmox 8 install, I had no issue running community.general.proxmox.

My playbook is like this :
Code:
- name: Download desired template
  community.general.proxmox_template:
    node: "{{ target_node }}"
    api_user: "{{ pve_cluster.user }}"
    api_password: "{{ pve_cluster.password }}"
    api_host: "{{ pve_cluster.hostname }}"
    storage: "{{ pve_cluster.template_storage }}"
    content_type: vztmpl
    template: "{{ ct_template }}"
# Le support pour les tags est en cours d'ajout, voir ici : https://github.com/ansible-collections/community.general/issues/5471
# On construit une liste ressemblant à ça :
# - service-_-none
# - service_version-_-latest
- name: On construit notre liste de tags
  ansible.builtin.set_fact:
    ct_tags_str: "{{ ct_tags_str | default([]) | union([[item.key, item.value] | join('-_-')]) }}"
  loop: "{{ ct_tags | dict2items }}"
- name: Création d'un container
  community.general.proxmox:
    hostname: "{{ ct_name }}"
    vmid: "{{ ct_vmid }}"
    node: "{{ target_node }}"
    api_user: "{{ pve_cluster.user }}"
    api_password: "{{ pve_cluster.password }}"
    api_host: "{{ pve_cluster.hostname }}"
    # Attention, les templates ne sont pas stockés dans le même storage
    ostemplate: "{{ pve_cluster.template_storage }}:vztmpl/{{ ct_template }}"
    storage: "{{ pve_cluster.data_storage }}"
    state: present
    onboot: true
    netif: { "net0": "name=eth0,bridge=vmbr1,ip=dhcp" }
    # On prend la clé publique de l'utilisateur en cours
    pubkey: "{{ ct_ssh_key }}"
    unprivileged: true
    features: "nesting=1"
    memory: "{{ ct_memory }}"
    cores: 1
    tags: "{{ ct_tags_str }}"
- name: On démarre le container
  community.general.proxmox:
    vmid: "{{ ct_vmid }}"
    api_user: "{{ pve_cluster.user }}"
    api_password: "{{ pve_cluster.password }}"
    api_host: "{{ pve_cluster.hostname }}"
    state: started
    unprivileged: true

I'm running :
  • proxmoxer 2.0.1
  • Python 3.11
  • ansible 2.15.4
  • community.general ansible package 8.2.0
Hope this helps,
 
  • Like
Reactions: flybyray