Skip to content

Commit

Permalink
one_vm: fix syntax error when creating VMs with a more complex template
Browse files Browse the repository at this point in the history
with more complex templates that make use of quoted strings the new
"render" method fails to produce a template that is accepted by
OpenNebula.  ==> escape double quotes in strings to make OpenNebula
happy again.

I also tested whether newlines need to be escaped, looks like they are
fine as they are.

Fixes ansible-collections#6225
  • Loading branch information
nilsding committed Apr 6, 2023
1 parent a64e368 commit e36f2f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6294-fix-one_vm-instantiation.yml
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions plugins/module_utils/opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/plugins/module_utils/test_opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
NIC=[NAME="NIC1",NETWORK_ID="1"]
''').strip()
),
(
{
'SCHED_REQUIREMENTS': 'CLUSTER_ID="100"',
},
textwrap.dedent('''
SCHED_REQUIREMENTS="CLUSTER_ID=\\"100\\""
''').strip()
)
]


Expand Down

0 comments on commit e36f2f7

Please sign in to comment.