Resolved issue with NetworkConfig parsing device configs with inconsistent indentation levels. (#51850)

pull/53989/head
blandrew 6 years ago committed by ansibot
parent 07774b4ccf
commit cfd869e898

@ -214,8 +214,7 @@ class NetworkConfig(object):
ancestors = list()
config = list()
curlevel = 0
prevlevel = 0
indents = [0]
for linenum, line in enumerate(to_native(lines, errors='surrogate_or_strict').split('\n')):
text = entry_reg.sub('', line).strip()
@ -228,20 +227,21 @@ class NetworkConfig(object):
# handle top level commands
if toplevel.match(line):
ancestors = [cfg]
prevlevel = curlevel
curlevel = 0
indents = [0]
# handle sub level commands
else:
match = childline.match(line)
line_indent = match.start(1)
prevlevel = curlevel
curlevel = int(line_indent / self._indent)
if line_indent < indents[-1]:
while indents[-1] > line_indent:
indents.pop()
if (curlevel - 1) > prevlevel:
curlevel = prevlevel + 1
if line_indent > indents[-1]:
indents.append(line_indent)
curlevel = len(indents) - 1
parent_level = curlevel - 1
cfg._parents = ancestors[:curlevel]

Loading…
Cancel
Save