From b1f33ca5a0c8c774e0db8d330b7bf9f1259c6aef Mon Sep 17 00:00:00 2001 From: GGabriele Date: Thu, 15 Sep 2016 13:15:40 +0200 Subject: [PATCH] Improved function --- .../modules/network/nxos/nxos_vtp_password.py | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vtp_password.py b/lib/ansible/modules/network/nxos/nxos_vtp_password.py index ff1991c0331..f53ff2ef6a6 100644 --- a/lib/ansible/modules/network/nxos/nxos_vtp_password.py +++ b/lib/ansible/modules/network/nxos/nxos_vtp_password.py @@ -366,17 +366,31 @@ def apply_key_map(key_map, table): def get_vtp_config(module): command = 'show vtp status' - body = execute_show_command(command, module) - vtp_parsed = {} - vtp_key = { - 'running-version': 'version', - 'domain_name': 'domain', - } + body = execute_show_command( + command, module, command_type='cli_show_ascii')[0] + vtp_parsed = {} if body: - vtp_parsed = apply_key_map(vtp_key, body[0]) - vtp_parsed['vtp_password'] = get_vtp_password(module) + version_regex = '.*VTP version running\s+:\s+(?P\d).*' + domain_regex = '.*VTP Domain Name\s+:\s+(?P\S+).*' + + try: + match_version = re.match(version_regex, body, re.DOTALL) + version = match_version.groupdict()['version'] + except AttributeError: + version = '' + + try: + match_domain = re.match(domain_regex, body, re.DOTALL) + domain = match_domain.groupdict()['domain'] + except AttributeError: + domain = '' + + if domain and version: + vtp_parsed['domain'] = domain + vtp_parsed['version'] = version + vtp_parsed['vtp_password'] = get_vtp_password(module) return vtp_parsed