fixes bugs in network filter for parsing ip address (#28404)

also adds parse_cli and parse_cli_textfsm to changelog
pull/24789/merge
Peter Sprygada 7 years ago committed by GitHub
parent 54c50cc983
commit 03b888052b

@ -128,6 +128,10 @@ Ansible Changes By Release
- profile_roles
- stderr
#### New Filters:
- parse_cli
- parse_cli_textfsm
#### New Inventory Plugins:
- advanced_host_list
- constructed_groups

@ -345,17 +345,22 @@ class Template:
self.env = Environment()
self.env.filters.update({'ternary': ternary})
def __call__(self, value, variables=None):
def __call__(self, value, variables=None, fail_on_undefined=True):
variables = variables or {}
if not self.contains_vars(value):
return value
try:
value = self.env.from_string(value).render(variables)
except UndefinedError:
if not fail_on_undefined:
return None
raise
if value:
try:
return ast.literal_eval(value)
except ValueError:
except:
return str(value)
else:
return None

@ -131,7 +131,13 @@ def parse_cli(output, tmpl):
else:
items.append(None)
objects.append(dict([(k, template(v, {'item': items})) for k, v in iteritems(value)]))
obj = {}
for k, v in iteritems(value):
try:
obj[k] = template(v, {'item': items}, fail_on_undefined=False)
except:
obj[k] = None
objects.append(obj)
elif isinstance(value, Mapping):
items = list()

Loading…
Cancel
Save