ansible/docs/docsite/rst/playbooks_lookups.rst

54 lines
2.3 KiB
ReStructuredText
Raw Normal View History

Lookups
-------
2012-05-13 17:00:02 +02:00
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.
2012-08-28 21:41:10 +02:00
.. note::
- Lookups occur on the local computer, not on the remote computer.
- They are executed with in the directory containing the role or play, as opposed to local tasks which are executed with the directory of the executed script.
- Since Ansible version 1.9, you can pass wantlist=True to lookups to use in jinja2 template "for" loops.
- Lookups are an advanced feature. You should have a good working knowledge of Ansible plays before incorporating them.
2015-02-20 00:15:10 +01:00
2017-01-10 21:46:17 +01:00
.. warning:: Some lookups pass arguments to a shell. When using variables from a remote/untrusted source, use the `|quote` filter to ensure safe usage.
.. contents:: Topics
.. _lookups_and_loops:
2013-10-05 00:41:14 +02:00
Lookups and loops
`````````````````
Various *lookup plugins* allow additional ways to iterate over data.
In :doc:`Loops <playbooks_loops>` you will learn how to use them to walk over collections of numerous types.
However, they can also be used to pull in data from remote sources, such as shell commands or even key value stores.
Before Ansible 2.5, lookups were mostly used indirectly in ``with_<lookup`` constructes for looping, begining in 2.5
we use them more explicitly as part of Jinja2 expressions fed into the ``loop`` keyword.
2012-05-13 17:00:02 +02:00
.. _lookups_and_variables:
Lookups and variables
`````````````````````
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 }}"
.. seealso::
:doc:`playbooks`
An introduction to playbooks
:doc:`playbooks_conditionals`
Conditional statements in playbooks
:doc:`playbooks_variables`
All about variables
:doc:`playbooks_loops`
Looping in playbooks
`User Mailing List <http://groups.google.com/group/ansible-devel>`_
Have a question? Stop by the google group!
`irc.freenode.net <http://irc.freenode.net>`_
#ansible IRC chat channel