From dbb145bc7167ad011f5b3a656747cd747e984a25 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 8 Nov 2020 13:31:21 +0100 Subject: [PATCH] lxc_container: fix the type of the 'container_config' parameter (#216) (#1247) * lxc_container: fix the type of the 'container_config' parameter * lxc_container: specify the type of elements in 'container_config' * lxc_container: improve the documentation of the container_config option * lxc_container: add changelogs fragment for PR 216 * lxc_container: update changelogs fragment for PR 216 Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit 9e51469e018e7ddb4ab92367e2d29e35991a0279) Co-authored-by: montag451 --- ...x-lxc-container-container_config-parameter.yaml | 2 ++ plugins/modules/cloud/lxc/lxc_container.py | 14 +++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/216-fix-lxc-container-container_config-parameter.yaml diff --git a/changelogs/fragments/216-fix-lxc-container-container_config-parameter.yaml b/changelogs/fragments/216-fix-lxc-container-container_config-parameter.yaml new file mode 100644 index 0000000000..ce3c175884 --- /dev/null +++ b/changelogs/fragments/216-fix-lxc-container-container_config-parameter.yaml @@ -0,0 +1,2 @@ +bugfixes: + - lxc_container - fix the type of the ``container_config`` parameter. It is now processed as a list and not a string (https://github.com/ansible-collections/community.general/pull/216). diff --git a/plugins/modules/cloud/lxc/lxc_container.py b/plugins/modules/cloud/lxc/lxc_container.py index 9aac710d7d..fef3d1aab3 100644 --- a/plugins/modules/cloud/lxc/lxc_container.py +++ b/plugins/modules/cloud/lxc/lxc_container.py @@ -143,6 +143,8 @@ options: container_config: description: - list of 'key=value' options to use when configuring a container. + type: list + elements: str requirements: - 'lxc >= 1.0 # OS package' - 'python >= 2.6 # OS Package' @@ -701,14 +703,7 @@ class LxcContainerManagement(object): with open(container_config_file, 'rb') as f: container_config = to_text(f.read(), errors='surrogate_or_strict').splitlines(True) - # Note used ast literal_eval because AnsibleModule does not provide for - # adequate dictionary parsing. - # Issue: https://github.com/ansible/ansible/issues/7679 - # TODO(cloudnull) adjust import when issue has been resolved. - import ast - options_dict = ast.literal_eval(_container_config) - parsed_options = [i.split('=', 1) for i in options_dict] - + parsed_options = [i.split('=', 1) for i in _container_config] config_change = False for key, value in parsed_options: key = key.strip() @@ -1695,7 +1690,8 @@ def main(): type='str' ), container_config=dict( - type='str' + type='list', + elements='str' ), container_log=dict( type='bool',