在Ansible的文档中,他们使用map
关键字:http://docs.ansible.com/set_fact_module.html
在Ansible的文档中,我找不到有关map
这是什么?
答案 0 :(得分:8)
在以下示例中:
# 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 }}"
map
实际上是一个Jinja2过滤器,可以根据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.
事实上,在{{ variable_name | something_here }}
之类的所有结构中,我们实际上都在说“将variable_name
传递给名为something_here
的过滤器”并返回结果。