1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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 <felix@fontein.de>

* Improved param description

* Use major.minor version comparison for options

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Sergei Antipov <s.antipov@mulesoft.com>
This commit is contained in:
nxet 2023-05-31 08:01:47 +02:00 committed by GitHub
parent 59db302deb
commit f71a474726
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- proxmox - support ``timezone`` parameter at container creation
(https://github.com/ansible-collections/community.general/pull/6510).

View file

@ -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']))