From da07b58c3b759cb6d8b86028f9c8e761c001f9f5 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 15 Oct 2018 11:34:35 +0530 Subject: [PATCH] Fix in confirmed_commit capability in netconf_config modules (#46964) * Fix in confirmed_commit capability in netconf_config modules Fixes #46804 * If confirm value is greater than zero or confirm_commit option is set and confirmed-commit capability is not supported but Netconf server only in that case fail the module * Update confirm-commit flag * Update changelog (cherry picked from commit 5394638047d9c11681ff7573e64d8b0a9c22f645) --- .../netconf_config_comfirm_commit_fix.yaml | 3 +++ .../modules/network/netconf/netconf_config.py | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/netconf_config_comfirm_commit_fix.yaml diff --git a/changelogs/fragments/netconf_config_comfirm_commit_fix.yaml b/changelogs/fragments/netconf_config_comfirm_commit_fix.yaml new file mode 100644 index 00000000000..c18589699f7 --- /dev/null +++ b/changelogs/fragments/netconf_config_comfirm_commit_fix.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: +- netconf_config - Fix in confirmed_commit capability in netconf_config modules (https://github.com/ansible/ansible/pull/46778) diff --git a/lib/ansible/modules/network/netconf/netconf_config.py b/lib/ansible/modules/network/netconf/netconf_config.py index f4c97b51945..d22a3be03eb 100644 --- a/lib/ansible/modules/network/netconf/netconf_config.py +++ b/lib/ansible/modules/network/netconf/netconf_config.py @@ -123,7 +123,7 @@ options: commit: description: - This boolean flag controls if the configuration changes should be committed or not after editing the - candidate datastore. This oprion is supported only if remote Netconf server supports :candidate + candidate datastore. This option is supported only if remote Netconf server supports :candidate capability. If the value is set to I(False) commit won't be issued after edit-config operation and user needs to handle commit or discard-changes explicitly. type: bool @@ -305,8 +305,8 @@ def main(): if confirm_commit and not operations.get('supports_confirm_commit', False): module.fail_json(msg='confirm commit is not supported by Netconf server') - if confirm_commit or (confirm > 0) and not operations.get('supports_confirm_commit', False): - module.fail_json(msg='confirm commit is not supported by this netconf server') + if (confirm > 0) and not operations.get('supports_confirm_commit', False): + module.fail_json(msg='confirm commit is not supported by this netconf server, given confirm timeout: %d' % confirm) if validate and not operations.get('supports_validate', False): module.fail_json(msg='validate is not supported by this netconf server') @@ -323,6 +323,7 @@ def main(): result = {'changed': False, 'server_capabilities': capabilities.get('server_capabilities', [])} before = None + after = None locked = False try: if module.params['backup']: @@ -362,15 +363,20 @@ def main(): 'error_option': module.params['error_option'], 'format': module.params['format'], } + conn.edit_config(**kwargs) + if supports_commit and module.params['commit']: + after = to_text(conn.get_config(source='candidate'), errors='surrogate_then_replace').strip() if not module.check_mode: - timeout = confirm if confirm > 0 else None - conn.commit(confirmed=confirm_commit, timeout=timeout) + confirm_timeout = confirm if confirm > 0 else None + confirmed_commit = True if confirm_timeout else False + conn.commit(confirmed=confirmed_commit, timeout=confirm_timeout) else: conn.discard_changes() - after = to_text(conn.get_config(source='running'), errors='surrogate_then_replace').strip() + if after is None: + after = to_text(conn.get_config(source='running'), errors='surrogate_then_replace').strip() sanitized_before = sanitize_xml(before) sanitized_after = sanitize_xml(after)