From 5bb876b0e21bb7b9e5a2e07f7a4a007264bcd122 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 23 Mar 2016 02:32:18 -0400 Subject: [PATCH] fixes issue with getting value with . (dot) in key in netcfg This commit addresses a problem when attempting to retrieve a value from the result that includes a dict key using . (dot). --- lib/ansible/module_utils/netcfg.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/ansible/module_utils/netcfg.py b/lib/ansible/module_utils/netcfg.py index 644a0a32dfa..5ccaf8d5bc3 100644 --- a/lib/ansible/module_utils/netcfg.py +++ b/lib/ansible/module_utils/netcfg.py @@ -85,9 +85,8 @@ def parse(lines, indent): class Conditional(object): - ''' - Used in command modules to evaluate waitfor conditions - ''' + """Used in command modules to evaluate waitfor conditions + """ OPERATORS = { 'eq': ['eq', '=='], @@ -133,13 +132,20 @@ class Conditional(object): raise AttributeError('unknown operator: %s' % oper) def get_value(self, result): - for key in self.key.split('.'): - match = re.match(r'^(.+)\[(\d+)\]', key) + parts = re.split(r'\.(?=[^\]]*(?:\[|$))', self.key) + for part in parts: + match = re.findall(r'\[(\S+?)\]', part) if match: - key, index = match.groups() - result = result[key][int(index)] + key = part[:part.find('[')] + result = result[key] + for m in match: + try: + m = int(m) + except ValueError: + m = str(m) + result = result[m] else: - result = result.get(key) + result = result.get(part) return result def number(self, value):