mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
54c50cc983
commit
03b888052b
3 changed files with 19 additions and 4 deletions
|
@ -128,6 +128,10 @@ Ansible Changes By Release
|
||||||
- profile_roles
|
- profile_roles
|
||||||
- stderr
|
- stderr
|
||||||
|
|
||||||
|
#### New Filters:
|
||||||
|
- parse_cli
|
||||||
|
- parse_cli_textfsm
|
||||||
|
|
||||||
#### New Inventory Plugins:
|
#### New Inventory Plugins:
|
||||||
- advanced_host_list
|
- advanced_host_list
|
||||||
- constructed_groups
|
- constructed_groups
|
||||||
|
|
|
@ -345,17 +345,22 @@ class Template:
|
||||||
self.env = Environment()
|
self.env = Environment()
|
||||||
self.env.filters.update({'ternary': ternary})
|
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 {}
|
variables = variables or {}
|
||||||
if not self.contains_vars(value):
|
if not self.contains_vars(value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
try:
|
||||||
value = self.env.from_string(value).render(variables)
|
value = self.env.from_string(value).render(variables)
|
||||||
|
except UndefinedError:
|
||||||
|
if not fail_on_undefined:
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
|
||||||
if value:
|
if value:
|
||||||
try:
|
try:
|
||||||
return ast.literal_eval(value)
|
return ast.literal_eval(value)
|
||||||
except ValueError:
|
except:
|
||||||
return str(value)
|
return str(value)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -131,7 +131,13 @@ def parse_cli(output, tmpl):
|
||||||
else:
|
else:
|
||||||
items.append(None)
|
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):
|
elif isinstance(value, Mapping):
|
||||||
items = list()
|
items = list()
|
||||||
|
|
Loading…
Reference in a new issue