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

also adds parse_cli and parse_cli_textfsm to changelog
This commit is contained in:
Peter Sprygada 2017-08-18 14:05:26 -04:00 committed by GitHub
parent 54c50cc983
commit 03b888052b
3 changed files with 19 additions and 4 deletions

View file

@ -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

View file

@ -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
value = self.env.from_string(value).render(variables)
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

View file

@ -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()