Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tags as module parameter to proxmox_kvm #2000

Merged
merged 9 commits into from
Mar 15, 2021

Conversation

Ajpantuso
Copy link
Collaborator

SUMMARY

New feature in proxmox_kvm plugin to allow VM tags to be passed as module parameters.

Fixes #1989

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

plugins/modules/cloud/misc/proxmox_kvm.py

ADDITIONAL INFORMATION

Tags are supplied as a yaml list of strings to the tags parameter.
Within the module tags are restricted to only Proxmox version >=6.
Tags are validated against the format provided by the proxmox devs and failed validation will fail the module indicating which tag is at fault.
Tags are joined with commas and then passed to proxmoxer as a tag-list-string,
CRUD operations function as expected for tags as well.

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added affects_2.10 cloud community_review feature This issue/PR relates to a feature request module module needs_triage plugins plugin (any type) labels Mar 12, 2021
@Ajpantuso Ajpantuso marked this pull request as ready for review March 12, 2021 01:19
@Ajpantuso Ajpantuso changed the title Adding tags as module parameter Adding tags as module parameter to proxmox_kvm Mar 12, 2021
Ajpantuso and others added 2 commits March 12, 2021 08:36
Co-authored-by: Felix Fontein <felix@fontein.de>
Original test was for key and not value

Co-authored-by: Felix Fontein <felix@fontein.de>
@felixfontein felixfontein added the check-before-release PR will be looked at again shortly before release and merged if possible. label Mar 12, 2021
@felixfontein
Copy link
Collaborator

Looks reasonable to me. @Aversiste @Thulium-Drake please take a look :)

@Ajpantuso
Copy link
Collaborator Author

I made some improvements regarding default behavior and tag nullification:

  • Set a default value of [""] for the tags parameter which indicates that tags should be left out of the update request altogether. (This makes it so that if users omit the tags parameter or set no value nothing changes)
  • Actually passed tags as a keyword argument to the create_vm function so it is correctly excluded if proxmox version < 6
  • Allowed users to set a VM's tags to empty by submitting an empty list as a value

Co-authored-by: Felix Fontein <felix@fontein.de>
@Ajpantuso
Copy link
Collaborator Author

Ajpantuso commented Mar 13, 2021

I made some improvements regarding default behavior and tag nullification:

  • Set a default value of [""] for the tags parameter which indicates that tags should be left out of the update request altogether. (This makes it so that if users omit the tags parameter or set no value nothing changes)
  • Actually passed tags as a keyword argument to the create_vm function so it is correctly excluded if proxmox version < 6
  • Allowed users to set a VM's tags to empty by submitting an empty list as a value

The default value was not necessary as the module already has sufficient handling for null parameters and has been removed.
The other two improvements are implemented however.

@Thulium-Drake
Copy link
Contributor

Thulium-Drake commented Mar 15, 2021

Like a charm! Still such a shame the devs do not expose this functionality, but that's on them ;-)

---
- name: 'create kvm'
  hosts: 'localhost'
  tasks:
    - name: Create new vm with minimal options
      community.general.proxmox_kvm:
        vmid: 999
        node: carrier
        api_user: ansible@pve
        api_password: whooohoooo
        api_host: carrier
        name: ansible-created
        storage: main
        tags: 'some,tags'
# cat /etc/pve/qemu-server/999.conf 
acpi: 1
autostart: 0
balloon: 0
boot: cnd
cpuunits: 1000
kvm: 1
name: ansible-created
ostype: l26
smbios1: uuid=26ec8a27-4717-4d02-be94-455ce8af787c
tablet: 0
tags: some,tags
template: 0
vga: std
vmgenid: d4c1aaaf-afd0-4a96-a05a-1297c1b2960e

LGTM

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Mar 15, 2021
@felixfontein felixfontein merged commit 0f61ae4 into ansible-collections:main Mar 15, 2021
patchback bot pushed a commit that referenced this pull request Mar 15, 2021
* Adding tags as module parameter

* Added changelog fragment

* Correcting typo in changelog fragment

* Correcting punctuation in docs

* Including version to tags parameter description

Co-authored-by: Felix Fontein <felix@fontein.de>

* Correct tag validation and parsing logic condition

Original test was for key and not value

Co-authored-by: Felix Fontein <felix@fontein.de>

* Improving usability with default null behavior

* Removing default case and related unneccessary complexity

* Display regex in tags description as code

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0f61ae4)
@felixfontein
Copy link
Collaborator

@Ajpantuso thanks for implementing this!
@Thulium-Drake thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Mar 15, 2021
* Adding tags as module parameter

* Added changelog fragment

* Correcting typo in changelog fragment

* Correcting punctuation in docs

* Including version to tags parameter description

Co-authored-by: Felix Fontein <felix@fontein.de>

* Correct tag validation and parsing logic condition

Original test was for key and not value

Co-authored-by: Felix Fontein <felix@fontein.de>

* Improving usability with default null behavior

* Removing default case and related unneccessary complexity

* Display regex in tags description as code

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0f61ae4)

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
@Ajpantuso Ajpantuso deleted the proxmox_kvm_tags branch March 17, 2021 01:41
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Apr 2, 2021
v3.2.0

community.crypto
- acme module_utils - the ``acme`` module_utils has been split up into several Python modules (ansible-collections/community.crypto#184).
- acme_* modules - codebase refactor which should not be visible to end-users (ansible-collections/community.crypto#184).
- acme_* modules - support account key passphrases for ``cryptography`` backend (ansible-collections/community.crypto#197, ansible-collections/community.crypto#207).
- acme_certificate_revoke - support revoking by private keys that are passphrase protected for ``cryptography`` backend (ansible-collections/community.crypto#207).
- acme_challenge_cert_helper - add ``private_key_passphrase`` parameter (ansible-collections/community.crypto#207).

community.docker
- docker_swarm_service - change ``publish.published_port`` option from mandatory to optional. Docker will assign random high port if not specified (ansible-collections/community.docker#99).

community.general
- archive - refactored some reused code out into a couple of functions (ansible-collections/community.general#2061).
- csv module utils - new module_utils for shared functions between ``from_csv`` filter and ``read_csv`` module (ansible-collections/community.general#2037).
- ipa_sudorule - add support for setting sudo runasuser (ansible-collections/community.general#2031).
- jenkins_job - add a ``validate_certs`` parameter that allows disabling TLS/SSL certificate validation (ansible-collections/community.general#255).
- kibana_plugin - add parameter for passing ``--allow-root`` flag to kibana and kibana-plugin commands (ansible-collections/community.general#2014).
- proxmox - added ``purge`` module parameter for use when deleting lxc's with HA options (ansible-collections/community.general#2013).
- proxmox inventory plugin - added ``tags_parsed`` fact containing tags parsed as a list (ansible-collections/community.general#1949).
- proxmox_kvm - added new module parameter ``tags`` for use with PVE 6+ (ansible-collections/community.general#2000).
- rax - elements of list parameters are now validated (ansible-collections/community.general#2006).
- rax_cdb_user - elements of list parameters are now validated (ansible-collections/community.general#2006).
- rax_scaling_group - elements of list parameters are now validated (ansible-collections/community.general#2006).
- read_csv - refactored read_csv module to use shared csv functions from csv module_utils (ansible-collections/community.general#2037).
- redfish_* modules, redfish_utils module utils - add support for Redfish session create, delete, and authenticate (ansible-collections/community.general#1975).
- snmp_facts - added parameters ``timeout`` and ``retries`` to module (ansible-collections/community.general#980).
- vdo - add ``force`` option (ansible-collections/community.general#2101).

community.network
- edgeos_config - match the space after ``set`` and ``delete`` commands (ansible-collections/community.network#199).
- nclu - execute ``net commit description <description>`` only if changed ``net pending``'s diff field (ansible-collections/community.network#219).

community.postgresql
- postgresql_info - add the ``patch``, ``full``, and ``raw`` values of the ``version`` return value (ansible-collections/community.postgresql#68).
- postgresql_ping - add the ``patch``, ``full``, and ``raw`` values of the ``server_version`` return value (ansible-collections/community.postgresql#70).

community.zabbix
- zabbix_agent - added support for installations on arm64 systems (ansible-collections/community.zabbix#320).
- zabbix_proxy - now supports configuring StatsAllowedIP (ansible-collections/community.zabbix#337).
- zabbix_server - added support for installtions on arm64 systems (ansible-collections/community.zabbix#320).
- zabbix_web - added support for installtions on arm64 systems (ansible-collections/community.zabbix#320).

dellemc.openmanage
- ome_template - Allows to deploy a template on device groups.

hetzner.hcloud
- Add firewalls to hcloud_server module

ovirt.ovirt
- cluster_upgrade - Add correlation-id header (oVirt/ovirt-ansible-collection#222).
- engine_setup - Add skip renew pki confirm (oVirt/ovirt-ansible-collection#228).
- examples - Add recipe for removing DM device (oVirt/ovirt-ansible-collection#233).
- hosted_engine_setup - Filter devices with unsupported bond mode (oVirt/ovirt-ansible-collection#226).
- infra - Add reboot host parameters (oVirt/ovirt-ansible-collection#231).
- ovirt_disk - Add SATA support (oVirt/ovirt-ansible-collection#225).
- ovirt_user - Add ssh_public_key (oVirt/ovirt-ansible-collection#232)

purestorage.flasharray
- purefa_maintenance - New module to set maintenance windows
- purefa_pg - Add support to rename protection groups
- purefa_syslog - Add support for naming SYSLOG servers for Purity//FA 6.1 or higher

purestorage.flashblade
- purefb_certs - Add update functionality for array cert
- purefb_fs - Add multiprotocol ACL support
- purefb_info - Add information regarding filesystem multiprotocol (where available)
- purefb_info - Add new parameter to provide details on admin users
- purefb_info - Add replication performace statistics
- purefb_s3user - Add ability to remove an S3 users existing access key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloud community_review feature This issue/PR relates to a feature request module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow tags to be supplied to proxmox_kvm on QEMU VM create
4 participants