From 844e194aa44abab728a89d1190a33c966e71bdcb Mon Sep 17 00:00:00 2001 From: vaneuk <31311894+vaneuk@users.noreply.github.com> Date: Tue, 29 Jan 2019 12:42:31 +0300 Subject: [PATCH] changed interface config blocks parsing logic (#50340) --- .../modules/network/iosxr/iosxr_interface.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/network/iosxr/iosxr_interface.py b/lib/ansible/modules/network/iosxr/iosxr_interface.py index b1ea971c33..3fc8a5392a 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_interface.py +++ b/lib/ansible/modules/network/iosxr/iosxr_interface.py @@ -297,14 +297,18 @@ class CliConfiguration(ConfigBase): def map_config_to_obj(self): data = get_config(self._module, config_filter='interface') - interfaces = data.strip().rstrip('!').split('!') + data_lines = data.splitlines() + start_indexes = [i for i, e in enumerate(data_lines) if e.startswith('interface')] + end_indexes = [i for i, e in enumerate(data_lines) if e == '!'] - if not interfaces: + intf_configs = list() + for start_index, end_index in zip(start_indexes, end_indexes): + intf_configs.append([i.strip() for i in data_lines[start_index:end_index]]) + + if not intf_configs: return list() - for interface in interfaces: - intf_config = interface.strip().splitlines() - + for intf_config in intf_configs: name = intf_config[0].strip().split()[1] active = 'act'