Lookup plugins allow access to outside data sources. Like all templating, these plugins are evaluated on the Ansible control machine, and can include reading the filesystem as well as contacting external datastores and services. This data is then made available using the standard templating system in Ansible.
Note
Warning
Some lookups pass arguments to a shell. When using variables from a remote/untrusted source, use the |quote
filter to ensure safe usage.
lookup plugins are a way to query external data sources, such as shell commands or even key value stores.
Before Ansible 2.5, lookups were mostly used indirectly in with_<lookup>
constructs for looping. Starting with Ansible version 2.5, lookups are used more explicitly as part of Jinja2 expressions fed into the loop
keyword.
One way of using lookups is to populate variables. These macros are evaluated each time they are used in a task (or template):
vars: motd_value: "{{ lookup('file', '/etc/motd') }}" tasks: - debug: msg: "motd value is {{ motd_value }}"
For more details and a complete list of lookup plugins available, please see Working With Plugins.
See also
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.9/user_guide/playbooks_lookups.html