From 76be9aa693a3feba957ae6944a7a2c43f070eeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Vali=C3=B1o=20Garc=C3=ADa?= Date: Mon, 12 Dec 2016 21:51:32 +0100 Subject: [PATCH] Fixes #18663. Bad handling of existing config in dellos9 module. (#18664) * Fixes #18663. Bad handling of existing config in dellos9 module. The dellos9 module doesn't build correctly the internal structures used to represent the existing config of the managed network device. This leads to apply changes every time the playbook is run, even if the existing config is the same that the one you are trying to push into the device. Probably this problem exist also in the dellos6 and dellos10 modules, but I only fixed it in the dellos9 module. The fix modifies two methods. The first one is `get_config`, where the return clause didn't work correctly when the flow doesn't enter in the `if` block. In that case the `contents` variable is not an array an this should be handled. The second fix is in the `get_sublevel_config` method. In this case the indentation whitespaces of the parents should be rebuild because further functions and methods required it to handle correctly comparisons used to check if changes should be pushed into device. * Fixes #18663 for dellos10 module with the same patches as dellos9. (cherry picked from commit 40ddbe026d74082d84a312d00ad2b367f4596b00) --- lib/ansible/module_utils/dellos10.py | 9 ++++++--- lib/ansible/module_utils/dellos9.py | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/ansible/module_utils/dellos10.py b/lib/ansible/module_utils/dellos10.py index 12c11cfe935..2b395a2a369 100644 --- a/lib/ansible/module_utils/dellos10.py +++ b/lib/ansible/module_utils/dellos10.py @@ -42,8 +42,9 @@ def get_config(module): if not contents: contents = module.config.get_config() module.params['config'] = contents - - return NetworkConfig(indent=1, contents=contents[0]) + return NetworkConfig(indent=1, contents=contents[0]) + else: + return NetworkConfig(indent=1, contents=contents) def get_sublevel_config(running_config, module): @@ -54,11 +55,13 @@ def get_sublevel_config(running_config, module): contents = obj.children contents[:0] = module.params['parents'] + indent = 0 for c in contents: if isinstance(c, str): - current_config_contents.append(c) + current_config_contents.append(c.rjust(len(c) + indent, ' ')) if isinstance(c, ConfigLine): current_config_contents.append(c.raw) + indent = indent + 1 sublevel_config = '\n'.join(current_config_contents) return sublevel_config diff --git a/lib/ansible/module_utils/dellos9.py b/lib/ansible/module_utils/dellos9.py index 7e4b0a482aa..b8add0e8145 100644 --- a/lib/ansible/module_utils/dellos9.py +++ b/lib/ansible/module_utils/dellos9.py @@ -42,8 +42,9 @@ def get_config(module): if not contents: contents = module.config.get_config() module.params['config'] = contents - - return NetworkConfig(indent=1, contents=contents[0]) + return NetworkConfig(indent=1, contents=contents[0]) + else: + return NetworkConfig(indent=1, contents=contents) def get_sublevel_config(running_config, module): @@ -54,11 +55,13 @@ def get_sublevel_config(running_config, module): contents = obj.children contents[:0] = module.params['parents'] + indent = 0 for c in contents: if isinstance(c, str): - current_config_contents.append(c) + current_config_contents.append(c.rjust(len(c) + indent, ' ')) if isinstance(c, ConfigLine): current_config_contents.append(c.raw) + indent = indent + 1 sublevel_config = '\n'.join(current_config_contents) return sublevel_config