diff --git a/CHANGELOG.md b/CHANGELOG.md index 60fcfd95934..bbc9c588028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ansible/module_utils/network_common.py b/lib/ansible/module_utils/network_common.py index 898618948a9..7d6f2be12ad 100644 --- a/lib/ansible/module_utils/network_common.py +++ b/lib/ansible/module_utils/network_common.py @@ -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 diff --git a/lib/ansible/plugins/filter/network.py b/lib/ansible/plugins/filter/network.py index 98dae86c609..50952b4fa29 100644 --- a/lib/ansible/plugins/filter/network.py +++ b/lib/ansible/plugins/filter/network.py @@ -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()