mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.2 KiB
ReStructuredText
55 lines
2.2 KiB
ReStructuredText
8 years ago
|
Lookups
|
||
|
-------
|
||
13 years ago
|
|
||
7 years ago
|
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.
|
||
12 years ago
|
|
||
7 years ago
|
.. note::
|
||
|
- Lookups occur on the local computer, not on the remote computer.
|
||
7 years ago
|
- 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.
|
||
7 years ago
|
- You can pass wantlist=True to lookups to use in jinja2 template "for" loops.
|
||
7 years ago
|
- Lookups are an advanced feature. You should have a good working knowledge of Ansible plays before incorporating them.
|
||
10 years ago
|
|
||
8 years ago
|
.. warning:: Some lookups pass arguments to a shell. When using variables from a remote/untrusted source, use the `|quote` filter to ensure safe usage.
|
||
8 years ago
|
|
||
11 years ago
|
.. contents:: Topics
|
||
|
|
||
7 years ago
|
.. _lookups_and_loops:
|
||
11 years ago
|
|
||
7 years ago
|
Lookups and loops
|
||
|
`````````````````
|
||
12 years ago
|
|
||
7 years ago
|
*lookup plugins* are a way to query external data sources, such as shell commands or even key value stores.
|
||
|
|
||
7 years ago
|
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.
|
||
13 years ago
|
|
||
|
|
||
7 years ago
|
.. _lookups_and_variables:
|
||
11 years ago
|
|
||
7 years ago
|
Lookups and variables
|
||
|
`````````````````````
|
||
11 years ago
|
|
||
7 years ago
|
One way of using lookups is to populate variables. These macros are evaluated each time they are used in a task (or template)::
|
||
12 years ago
|
|
||
|
vars:
|
||
12 years ago
|
motd_value: "{{ lookup('file', '/etc/motd') }}"
|
||
12 years ago
|
tasks:
|
||
7 years ago
|
- debug:
|
||
|
msg: "motd value is {{ motd_value }}"
|
||
12 years ago
|
|
||
7 years ago
|
For more details and a complete list of lookup plugins available, please see :doc:`plugins/lookup`.
|
||
|
|
||
11 years ago
|
.. 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
|