diff --git a/changelogs/fragments/6294-fix-one_vm-instantiation.yml b/changelogs/fragments/6294-fix-one_vm-instantiation.yml new file mode 100644 index 00000000000..dbe98f1ef08 --- /dev/null +++ b/changelogs/fragments/6294-fix-one_vm-instantiation.yml @@ -0,0 +1,2 @@ +bugfixes: + - one_vm - fix syntax error when creating VMs with a more complex template (https://github.com/ansible-collections/community.general/issues/6225) diff --git a/plugins/module_utils/opennebula.py b/plugins/module_utils/opennebula.py index 0fe649ba5c0..0c6228cc528 100644 --- a/plugins/module_utils/opennebula.py +++ b/plugins/module_utils/opennebula.py @@ -52,6 +52,9 @@ def recurse(to_render): for item in value: yield '{0:}=[{1:}]'.format(key, ','.join(recurse(item))) continue + if isinstance(value, str): + yield '{0:}="{1:}"'.format(key, value.replace('"', '\\"')) + continue yield '{0:}="{1:}"'.format(key, value) return '\n'.join(recurse(to_render)) diff --git a/tests/unit/plugins/module_utils/test_opennebula.py b/tests/unit/plugins/module_utils/test_opennebula.py index 550d403711a..1fc26eb1231 100644 --- a/tests/unit/plugins/module_utils/test_opennebula.py +++ b/tests/unit/plugins/module_utils/test_opennebula.py @@ -75,6 +75,14 @@ NIC=[NAME="NIC1",NETWORK_ID="1"] ''').strip() ), + ( + { + 'SCHED_REQUIREMENTS': 'CLUSTER_ID="100"', + }, + textwrap.dedent(''' + SCHED_REQUIREMENTS="CLUSTER_ID=\\"100\\"" + ''').strip() + ) ]