Skip to content

Commit

Permalink
proxmox - fixing onboot parameter causing module failure when not def…
Browse files Browse the repository at this point in the history
…ined (#3874)

* fixing onboot parameter when not supplied

* adding changelog fragment
  • Loading branch information
Ajpantuso authored Dec 14, 2021
1 parent 8825ef4 commit 00a1152
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/3874-proxmox-fix-onboot-param.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- proxmox - fixed ``onboot`` parameter causing module failures when undefined
(https://github.com/ansible-collections/community.general/issues/3844).
11 changes: 11 additions & 0 deletions plugins/module_utils/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 7 additions & 3 deletions plugins/modules/cloud/misc/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@
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

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

Expand Down

0 comments on commit 00a1152

Please sign in to comment.