ansible-collections / community.general

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

Improve Proxmox volume handling #8542

Open Lithimlin opened 2 weeks ago

Lithimlin commented 2 weeks ago
SUMMARY

Fixes #8407

Makes the creation of new volumes idempotent and adds new keys with better readability.

ISSUE TYPE
COMPONENT NAME

proxmox

ADDITIONAL INFORMATION

Here is a sample playbook to test the new features/bug fixes:

---
- name: Create LXC
  hosts: localhost
  become: false
  gather_facts: false
  vars_files:
    - proxmox_credentials.yml
  tasks:
    - name: Create LXC
      community.general.proxmox:
        api_host: "{{ api_host }}"
        api_user: "{{ api_user }}"
        api_password: "{{ api_password }}"
        # api_token_id: "{{ api_token_id }}"
        # api_token_secret: "{{ api_token_secret }}"
        node: "{{ node }}"
        hostname: test-node
        ostemplate: local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst
        disk: local-lvm:8
      register: create_res

    - name: Update LXC config [new - create volumes]
      community.general.proxmox:
        api_host: "{{ api_host }}"
        api_user: "{{ api_user }}"
        api_password: "{{ api_password }}"
        # api_token_id: "{{ api_token_id }}"
        # api_token_secret: "{{ api_token_secret }}"
        node: "{{ node }}"
        hostname: test-node
        cores: 1
        vmid: "{{ create_res.vmid }}"
        disk_volume:
          storage: local-lvm
          size: 14
        mount_volumes:
          - id: mp0
            storage: local-lvm
            size: 3
            mountpoint: /mnt/test
          - id: mp1
            host_path: /root/test
            mountpoint: /mnt/host
            options:
              backup: "0"
        update: true

    - name: Update LXC config [new - explicit volumes]
      community.general.proxmox:
        api_host: "{{ api_host }}"
        api_user: "{{ api_user }}"
        api_password: "{{ api_password }}"
        # api_token_id: "{{ api_token_id }}"
        # api_token_secret: "{{ api_token_secret }}"
        node: "{{ node }}"
        hostname: test-node
        cores: 1
        vmid: "{{ create_res.vmid }}"
        disk_volume:
          storage: local-lvm
          volume: "vm-{{ create_res.vmid }}-disk-0"
          size: 14
        mount_volumes:
          - id: mp0
            storage: local-lvm
            volume: "vm-{{ create_res.vmid }}-disk-1"
            size: 3
            mountpoint: /mnt/test
          - id: mp1
            host_path: /root/test
            mountpoint: /mnt/host
            options:
              backup: "0"
        update: true

    - name: Update LXC config [old - implicit volumes]
      community.general.proxmox:
        api_host: "{{ api_host }}"
        api_user: "{{ api_user }}"
        api_password: "{{ api_password }}"
        # api_token_id: "{{ api_token_id }}"
        # api_token_secret: "{{ api_token_secret }}"
        node: "{{ node }}"
        hostname: test-node
        cores: 1
        vmid: "{{ create_res.vmid }}"
        disk: local-lvm:14
        mounts: '{"mp0":"local-lvm:3,mp=/mnt/test","mp1":"/root/test,mp=/mnt/host,backup=0"}'
        update: true

    - name: Update LXC config [old - explicit volumes]
      community.general.proxmox:
        api_host: "{{ api_host }}"
        api_user: "{{ api_user }}"
        api_password: "{{ api_password }}"
        # api_token_id: "{{ api_token_id }}"
        # api_token_secret: "{{ api_token_secret }}"
        node: "{{ node }}"
        hostname: test-node
        cores: 1
        vmid: "{{ create_res.vmid }}"
        disk: "local-lvm:vm-{{ create_res.vmid }}-disk-0,size=14G"
        mounts: '{"mp0":"local-lvm:vm-{{ create_res.vmid }}-disk-1,size=3G,mp=/mnt/test","mp1":"/root/test,mp=/mnt/host,backup=0"}'
        update: true

Note: To test bind mounting, we actually need to use the root@pam user with its password. Even a token owned by that user will not work due to missing permissions.

Output:

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Create LXC] *******************************************************************************************************************************************************************

TASK [Create LXC] *******************************************************************************************************************************************************************
ok: [localhost]

TASK [Update LXC config [new - create volumes]] *************************************************************************************************************************************
changed: [localhost]

TASK [Update LXC config [new - explicit volumes]] ***********************************************************************************************************************************
ok: [localhost]

TASK [Update LXC config [old - implicit volumes]] ***********************************************************************************************************************************
ok: [localhost]

TASK [Update LXC config [old - explicit volumes]] ***********************************************************************************************************************************
ok: [localhost]

PLAY RECAP **************************************************************************************************************************************************************************
localhost                  : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  
ansibullbot commented 2 weeks ago

The test ansible-test sanity --test compile --python 2.7 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: SyntaxError: **kwargs,

The test ansible-test sanity --test import --python 2.7 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: traceback: SyntaxError: invalid syntax

The test ansible-test sanity --test compile --python 2.7 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: SyntaxError: **kwargs,

The test ansible-test sanity --test compile --python 3.5 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: SyntaxError: **kwargs,

The test ansible-test sanity --test import --python 2.7 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: traceback: SyntaxError: invalid syntax

The test ansible-test sanity --test import --python 3.5 [explain] failed with 1 error:

plugins/modules/proxmox.py:696:21: traceback: SyntaxError: invalid syntax

click here for bot help

ansibullbot commented 2 weeks ago

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

ansibullbot commented 6 days ago

The test extra-docs failed with 17 errors:

plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> disk_volume -> suboptions -> host_path -> description[1]: O(host_path): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> disk_volume -> suboptions -> options -> description[1]: O(options): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> disk_volume -> suboptions -> size -> description[1]: O(size): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> disk_volume -> suboptions -> volume -> description[1]: O(volume): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[1]: O(host_path): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.[].size): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.[].storage): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.[].volume): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> id -> description[1]: O(id): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> mountpoint -> description[1]: O(mountpoint): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> options -> description[1]: O(options): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[1]: O(size): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[3]: O(mount_volumes.[].host_path): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[3]: O(mount_volumes.[].storage): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> storage -> description[2]: O(mount_volumes.[].host_path): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> volume -> description[1]: O(volume): option name does not reference to an existing option of the module community.general.proxmox
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> volume -> description[4]: O(mount_volumes.[].host_path): option name does not reference to an existing option of the module community.general.proxmox

The test ansible-test sanity --test validate-modules [explain] failed with 10 errors:

plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(host_path)" contains a non-existing option "host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(id)" contains a non-existing option "id"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].host_path)" contains a non-existing option "mount_volumes.[].host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].size)" contains a non-existing option "mount_volumes.[].size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].storage)" contains a non-existing option "mount_volumes.[].storage"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].volume)" contains a non-existing option "mount_volumes.[].volume"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mountpoint)" contains a non-existing option "mountpoint"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(options)" contains a non-existing option "options"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(size)" contains a non-existing option "size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(volume)" contains a non-existing option "volume"

The test ansible-test sanity --test validate-modules [explain] failed with 10 errors:

plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(host_path)" contains a non-existing option "host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(id)" contains a non-existing option "id"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].host_path)" contains a non-existing option "mount_volumes.[].host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].size)" contains a non-existing option "mount_volumes.[].size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].storage)" contains a non-existing option "mount_volumes.[].storage"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].volume)" contains a non-existing option "mount_volumes.[].volume"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mountpoint)" contains a non-existing option "mountpoint"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(options)" contains a non-existing option "options"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(size)" contains a non-existing option "size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(volume)" contains a non-existing option "volume"

The test ansible-test sanity --test validate-modules [explain] failed with 10 errors:

plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(host_path)" contains a non-existing option "host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(id)" contains a non-existing option "id"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].host_path)" contains a non-existing option "mount_volumes.[].host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].size)" contains a non-existing option "mount_volumes.[].size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].storage)" contains a non-existing option "mount_volumes.[].storage"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].volume)" contains a non-existing option "mount_volumes.[].volume"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mountpoint)" contains a non-existing option "mountpoint"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(options)" contains a non-existing option "options"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(size)" contains a non-existing option "size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(volume)" contains a non-existing option "volume"

The test ansible-test sanity --test validate-modules [explain] failed with 10 errors:

plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(host_path)" contains a non-existing option "host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(id)" contains a non-existing option "id"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].host_path)" contains a non-existing option "mount_volumes.[].host_path"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].size)" contains a non-existing option "mount_volumes.[].size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].storage)" contains a non-existing option "mount_volumes.[].storage"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mount_volumes.[].volume)" contains a non-existing option "mount_volumes.[].volume"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(mountpoint)" contains a non-existing option "mountpoint"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(options)" contains a non-existing option "options"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(size)" contains a non-existing option "size"
plugins/modules/proxmox.py:0:0: invalid-documentation-markup: Directive "O(volume)" contains a non-existing option "volume"

click here for bot help

ansibullbot commented 6 days ago

The test extra-docs failed with 15 errors:

plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[1]: O(mount_volumes.host_path): option name 'mount_volumes.host_path' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.size): option name 'mount_volumes.size' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.storage): option name 'mount_volumes.storage' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> host_path -> description[2]: O(mount_volumes.volume): option name 'mount_volumes.volume' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> id -> description[1]: O(mount_volumes.id): option name 'mount_volumes.id' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> mountpoint -> description[1]: O(mount_volumes.mountpoint): option name 'mount_volumes.mountpoint' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> options -> description[1]: O(mount_volumes.options): option name 'mount_volumes.options' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[1]: O(mount_volumes.size): option name 'mount_volumes.size' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[3]: O(mount_volumes.host_path): option name 'mount_volumes.host_path' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> size -> description[3]: O(mount_volumes.storage): option name 'mount_volumes.storage' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> storage -> description[1]: O(mount_volumes.storage): option name 'mount_volumes.storage' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> storage -> description[2]: O(mount_volumes.host_path): option name 'mount_volumes.host_path' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> volume -> description[1]: O(mount_volumes.volume): option name 'mount_volumes.volume' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> volume -> description[4]: O(mount_volumes.host_path): option name 'mount_volumes.host_path' refers to list mount_volumes without `[]`
plugins/modules/proxmox.py:0:0: DOCUMENTATION -> options -> mount_volumes -> suboptions -> volume -> description[4]: O(mount_volumes.storage): option name 'mount_volumes.storage' refers to list mount_volumes without `[]`

click here for bot help