What is a 'map' in terms of Ansible variables?

27.4k views Asked by At

In Ansible's documentation, they are using the map keyword: http://docs.ansible.com/set_fact_module.html

In Ansible's documentation, I cannot find any information about map

What is it?

1

There are 1 answers

1
AudioBubble On BEST ANSWER

In the example of:

# Example setting host facts using complex arguments
- set_fact:
     one_fact: something
     other_fact: "{{ local_var * 2 }}"
     another_fact: "{{ some_registered_var.results | map(attribute='ansible_facts.some_fact') | list }}"

the map is actually a Jinja2 filter and more information can be found per the Jinja2 official documentation:

map()
    Applies a filter on a sequence of objects or looks up an attribute. 
    This is useful when dealing with lists of objects but you are really 
    only interested in a certain value of it.

In fact, in all constructions such as {{ variable_name | something_here }}, we're actually saying "pass variable_name to the filter named something_here" and return the result.