就 Ansible 变量而言,'map' 是什么?
What is a 'map' in terms of Ansible variables?
在 Ansible 的文档中,他们使用 map
关键字:http://docs.ansible.com/set_fact_module.html
在 Ansible 的文档中,我找不到任何关于 map
的信息
这是什么?
例如:
# 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
的过滤器”,然后 return 结果。
在 Ansible 的文档中,他们使用 map
关键字:http://docs.ansible.com/set_fact_module.html
在 Ansible 的文档中,我找不到任何关于 map
这是什么?
例如:
# 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
的过滤器”,然后 return 结果。