Skip to content

Commit 86a5b4f

Browse files
proxmox - fixing onboot parameter causing module failure when not defined (#3874) (#3901)
* fixing onboot parameter when not supplied * adding changelog fragment (cherry picked from commit 00a1152) Co-authored-by: Andrew Pantuso <ajpantuso@gmail.com>
1 parent 4e14c42 commit 86a5b4f

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
bugfixes:
3+
- proxmox - fixed ``onboot`` parameter causing module failures when undefined
4+
(https://github.com/ansible-collections/community.general/issues/3844).

plugins/module_utils/proxmox.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ def proxmox_to_ansible_bool(value):
5454
return True if value == 1 else False
5555

5656

57+
def ansible_to_proxmox_bool(value):
58+
'''Convert Ansible representation of a boolean to be proxmox-friendly'''
59+
if value is None:
60+
return None
61+
62+
if not isinstance(value, bool):
63+
raise ValueError("%s must be of type bool not %s" % (value, type(value)))
64+
65+
return 1 if value else 0
66+
67+
5768
class ProxmoxAnsible(object):
5869
"""Base class for Proxmox modules"""
5970
def __init__(self, module):

plugins/modules/cloud/misc/proxmox.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@
374374
from ansible.module_utils.basic import AnsibleModule, env_fallback
375375
from ansible.module_utils.common.text.converters import to_native
376376

377+
from ansible_collections.community.general.plugins.module_utils.proxmox import (
378+
ansible_to_proxmox_bool
379+
)
380+
377381

378382
VZ_TYPE = None
379383

@@ -627,14 +631,14 @@ def main():
627631
netif=module.params['netif'],
628632
mounts=module.params['mounts'],
629633
ip_address=module.params['ip_address'],
630-
onboot=int(module.params['onboot']),
634+
onboot=ansible_to_proxmox_bool(module.params['onboot']),
631635
cpuunits=module.params['cpuunits'],
632636
nameserver=module.params['nameserver'],
633637
searchdomain=module.params['searchdomain'],
634-
force=int(module.params['force']),
638+
force=ansible_to_proxmox_bool(module.params['force']),
635639
pubkey=module.params['pubkey'],
636640
features=",".join(module.params['features']) if module.params['features'] is not None else None,
637-
unprivileged=int(module.params['unprivileged']),
641+
unprivileged=ansible_to_proxmox_bool(module.params['unprivileged']),
638642
description=module.params['description'],
639643
hookscript=module.params['hookscript'])
640644

0 commit comments

Comments
 (0)