From b4275969c149b5fa7d4589d267b52cc1c87a1e79 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 08:52:20 +0200 Subject: [PATCH] [PR #6510/f71a4747 backport][stable-7] proxmox: support param `timezone` when creating container (#6611) proxmox: support param `timezone` when creating container (#6510) * proxmox: support param `timezone` when creating container * add changelog fragments for #6510 * Apply suggestions from code review Co-authored-by: Felix Fontein * Improved param description * Use major.minor version comparison for options --------- Co-authored-by: Felix Fontein Co-authored-by: Sergei Antipov (cherry picked from commit f71a4747260164ae533d6795cfb0094f025abeb9) Co-authored-by: nxet --- .../6510-proxmox-create-support_timezone.yaml | 3 ++ plugins/modules/proxmox.py | 32 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/6510-proxmox-create-support_timezone.yaml diff --git a/changelogs/fragments/6510-proxmox-create-support_timezone.yaml b/changelogs/fragments/6510-proxmox-create-support_timezone.yaml new file mode 100644 index 0000000000..5e399c9ebc --- /dev/null +++ b/changelogs/fragments/6510-proxmox-create-support_timezone.yaml @@ -0,0 +1,3 @@ +minor_changes: + - proxmox - support ``timezone`` parameter at container creation + (https://github.com/ansible-collections/community.general/pull/6510). diff --git a/plugins/modules/proxmox.py b/plugins/modules/proxmox.py index 1f685f01b0..2c1d45dd41 100644 --- a/plugins/modules/proxmox.py +++ b/plugins/modules/proxmox.py @@ -168,6 +168,12 @@ options: - Script that will be executed during various steps in the containers lifetime. type: str version_added: '0.2.0' + timezone: + description: + - Timezone used by the container, accepts values like C(Europe/Paris). + - The special value C(host) configures the same timezone used by Proxmox host. + type: str + version_added: '7.1.0' proxmox_default_behavior: description: - As of community.general 4.0.0, various options no longer have default values. @@ -314,6 +320,18 @@ EXAMPLES = r''' ostemplate: local:vztmpl/ubuntu-14.04-x86_64.tar.gz' cores: 2 +- name: Create new container with minimal options and same timezone as proxmox host + community.general.proxmox: + vmid: 100 + node: uk-mc02 + api_user: root@pam + api_password: 1q2w3e + api_host: node1 + password: 123456 + hostname: example.org + ostemplate: 'local:vztmpl/ubuntu-14.04-x86_64.tar.gz' + timezone: host + - name: Create a new container with nesting enabled and allows the use of CIFS/NFS inside the container. community.general.proxmox: vmid: 100 @@ -432,21 +450,21 @@ class ProxmoxLxcAnsible(ProxmoxAnsible): # Version limited features minimum_version = { - 'tags': 7, + 'tags': '6.1', + 'timezone': '6.3' } proxmox_node = self.proxmox_api.nodes(node) # Remove all empty kwarg entries kwargs = dict((k, v) for k, v in kwargs.items() if v is not None) - version = self.version() - pve_major_version = 3 if version < LooseVersion('4.0') else version.version[0] + pve_version = self.version() # Fail on unsupported features for option, version in minimum_version.items(): - if pve_major_version < version and option in kwargs: - self.module.fail_json(changed=False, msg="Feature {option} is only supported in PVE {version}+, and you're using PVE {pve_major_version}". - format(option=option, version=version, pve_major_version=pve_major_version)) + if pve_version < LooseVersion(version) and option in kwargs: + self.module.fail_json(changed=False, msg="Feature {option} is only supported in PVE {version}+, and you're using PVE {pve_version}". + format(option=option, version=version, pve_version=pve_version)) if VZ_TYPE == 'lxc': kwargs['cpulimit'] = cpus @@ -602,6 +620,7 @@ def main(): unprivileged=dict(type='bool', default=True), description=dict(type='str'), hookscript=dict(type='str'), + timezone=dict(type='str'), proxmox_default_behavior=dict(type='str', default='no_defaults', choices=['compatibility', 'no_defaults']), clone=dict(type='int'), clone_type=dict(default='opportunistic', choices=['full', 'linked', 'opportunistic']), @@ -704,6 +723,7 @@ def main(): unprivileged=ansible_to_proxmox_bool(module.params['unprivileged']), description=module.params['description'], hookscript=module.params['hookscript'], + timezone=module.params['timezone'], tags=module.params['tags']) module.exit_json(changed=True, msg="Deployed VM %s from template %s" % (vmid, module.params['ostemplate']))