From 00a1152bb1e4a650b823c3cc1157f32e7c710ea4 Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Tue, 14 Dec 2021 00:46:49 -0500 Subject: [PATCH] proxmox - fixing onboot parameter causing module failure when not defined (#3874) * fixing onboot parameter when not supplied * adding changelog fragment --- .../fragments/3874-proxmox-fix-onboot-param.yml | 4 ++++ plugins/module_utils/proxmox.py | 11 +++++++++++ plugins/modules/cloud/misc/proxmox.py | 10 +++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/3874-proxmox-fix-onboot-param.yml diff --git a/changelogs/fragments/3874-proxmox-fix-onboot-param.yml b/changelogs/fragments/3874-proxmox-fix-onboot-param.yml new file mode 100644 index 0000000000..705174dd5d --- /dev/null +++ b/changelogs/fragments/3874-proxmox-fix-onboot-param.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - proxmox - fixed ``onboot`` parameter causing module failures when undefined + (https://github.com/ansible-collections/community.general/issues/3844). diff --git a/plugins/module_utils/proxmox.py b/plugins/module_utils/proxmox.py index 666f87777a..a36991225b 100644 --- a/plugins/module_utils/proxmox.py +++ b/plugins/module_utils/proxmox.py @@ -54,6 +54,17 @@ def proxmox_to_ansible_bool(value): return True if value == 1 else False +def ansible_to_proxmox_bool(value): + '''Convert Ansible representation of a boolean to be proxmox-friendly''' + if value is None: + return None + + if not isinstance(value, bool): + raise ValueError("%s must be of type bool not %s" % (value, type(value))) + + return 1 if value else 0 + + class ProxmoxAnsible(object): """Base class for Proxmox modules""" def __init__(self, module): diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py index 710f028345..0fb7f1ccae 100644 --- a/plugins/modules/cloud/misc/proxmox.py +++ b/plugins/modules/cloud/misc/proxmox.py @@ -359,6 +359,10 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule, env_fallback from ansible.module_utils.common.text.converters import to_native +from ansible_collections.community.general.plugins.module_utils.proxmox import ( + ansible_to_proxmox_bool +) + VZ_TYPE = None @@ -605,14 +609,14 @@ def main(): netif=module.params['netif'], mounts=module.params['mounts'], ip_address=module.params['ip_address'], - onboot=int(module.params['onboot']), + onboot=ansible_to_proxmox_bool(module.params['onboot']), cpuunits=module.params['cpuunits'], nameserver=module.params['nameserver'], searchdomain=module.params['searchdomain'], - force=int(module.params['force']), + force=ansible_to_proxmox_bool(module.params['force']), pubkey=module.params['pubkey'], features=",".join(module.params['features']) if module.params['features'] is not None else None, - unprivileged=int(module.params['unprivileged']), + unprivileged=ansible_to_proxmox_bool(module.params['unprivileged']), description=module.params['description'], hookscript=module.params['hookscript'])