Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Ansible's extract filter is supposedly made for use in map, but at the time of writing the documentation doesn't actually show how to use it together with the map filter. The following outputs VAR...
Question
ansible
#2: Post edited
- Ansible's [extract](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/extract_filter.html) filter is supposedly made for use in [map](https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.map), but at the time of writing the documentation doesn't actually show how to use it together with the map filter.
- The following outputs _VARIABLE IS NOT DEFINED!_, so clearly it's missing something. I would like it to output _[1, 2]_.
```ansible- - name: Extraction test
- vars:
- dictionary:
- one: 1
- two: 2
- key_list:
- - one
- - two
- extracted: "{{ key_list | map('extract', 'dictionary') }}"
- ansible.builtin.debug:
- var: extracted
- ```
- Ansible's [extract](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/extract_filter.html) filter is supposedly made for use in [map](https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.map), but at the time of writing the documentation doesn't actually show how to use it together with the map filter.
- The following outputs _VARIABLE IS NOT DEFINED!_, so clearly it's missing something. I would like it to output _[1, 2]_.
- ```yaml
- - name: Extraction test
- vars:
- dictionary:
- one: 1
- two: 2
- key_list:
- - one
- - two
- extracted: "{{ key_list | map('extract', 'dictionary') }}"
- ansible.builtin.debug:
- var: extracted
- ```
#1: Initial revision
How to use Ansible extract filter in map with an external dictionary
Ansible's [extract](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/extract_filter.html) filter is supposedly made for use in [map](https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.map), but at the time of writing the documentation doesn't actually show how to use it together with the map filter. The following outputs _VARIABLE IS NOT DEFINED!_, so clearly it's missing something. I would like it to output _[1, 2]_. ```ansible - name: Extraction test vars: dictionary: one: 1 two: 2 key_list: - one - two extracted: "{{ key_list | map('extract', 'dictionary') }}" ansible.builtin.debug: var: extracted ```