Revert "Add a get_nested filter"
This reverts commit 80a1262252
because we're not using it, and using json_query is simple enough.
Change-Id: I8d5fba867eceb6892a7a995a9b86153e88353480
This commit is contained in:
parent
80a1262252
commit
1e436a2f43
|
@ -317,34 +317,6 @@ def git_link_parse_name(repo):
|
|||
|
||||
return git_link_parse(repo)['name']
|
||||
|
||||
def get_nested(target_dict, keys):
|
||||
"""Retrieves values through a nested dictionary.
|
||||
|
||||
If any key on the path is missing, return None
|
||||
|
||||
This helps solves convoluted guards in roles/plays such as the following:
|
||||
|
||||
('openstack_ansible' not in ansible_local or
|
||||
'swift' not in ansible_local['openstack_ansible'] or
|
||||
'venv_tag' not in ansible_local['openstack_ansible']['swift'] or
|
||||
ansible_local['openstack_ansible']['swift']['venv_tag'] == swift_venv_tag)
|
||||
|
||||
With this filter, it could be instead written:
|
||||
ansible_local|get_nested('openstack_ansible.swift.venv_tag') == swift_venv_tag
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
key, next_keys = keys.split('.', 1)
|
||||
except ValueError:
|
||||
return target_dict.get(keys, None)
|
||||
|
||||
try:
|
||||
next_dict = target_dict[key]
|
||||
except KeyError:
|
||||
return None
|
||||
return get_nested(next_dict, next_keys)
|
||||
|
||||
|
||||
class FilterModule(object):
|
||||
"""Ansible jinja2 filters."""
|
||||
|
@ -363,6 +335,5 @@ class FilterModule(object):
|
|||
'filtered_list': filtered_list,
|
||||
'git_link_parse': git_link_parse,
|
||||
'git_link_parse_name': git_link_parse_name,
|
||||
'deprecated': _deprecated,
|
||||
'get_nested': get_nested
|
||||
'deprecated': _deprecated
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
deprecations:
|
||||
- |
|
||||
The ``get_gested`` filter has been removed, as it is not used by any
|
||||
roles/plays.
|
|
@ -120,18 +120,3 @@
|
|||
- name: Validate deprecated filter
|
||||
assert:
|
||||
that: "deprecated_value == old_var"
|
||||
|
||||
- name: Set test_dict fact
|
||||
set_fact:
|
||||
test_dict:
|
||||
a:
|
||||
b:
|
||||
c: d
|
||||
|
||||
- name: Validate get_nested returns value
|
||||
assert:
|
||||
that: "{{ test_dict|get_nested('a.b.c') == 'd' }}"
|
||||
|
||||
- name: Validate get_nested returns None on missing key
|
||||
assert:
|
||||
that: "{{ test_dict|get_nested('a.c') == None }}"
|
||||
|
|
Loading…
Reference in New Issue