fixed some link nits (#65772)

This commit is contained in:
Sandra McCann 2019-12-12 14:20:08 -05:00 committed by Alicia Cozine
parent 860cacc54f
commit 9c30325704

View file

@ -82,7 +82,7 @@ Either of these examples would be the equivalent of::
state: present state: present
groups: "wheel" groups: "wheel"
You can pass a list directly to a parameter for some plugins. Most of the packaging modules, like :ref:`yum_module` and :ref:`apt_module`, have this capability. When available, passing the list to a parameter is better than looping over the task. For example:: You can pass a list directly to a parameter for some plugins. Most of the packaging modules, like :ref:`yum <yum_module>` and :ref:`apt <apt_module>`, have this capability. When available, passing the list to a parameter is better than looping over the task. For example::
- name: optimal yum - name: optimal yum
yum: yum:
@ -111,13 +111,15 @@ If you have a list of hashes, you can reference subkeys in a loop. For example::
- { name: 'testuser1', groups: 'wheel' } - { name: 'testuser1', groups: 'wheel' }
- { name: 'testuser2', groups: 'root' } - { name: 'testuser2', groups: 'root' }
When combining :ref:`playbooks_conditionals` with a loop, the ``when:`` statement is processed separately for each item. When combining :ref:`conditionals <playbooks_conditionals>` with a loop, the ``when:`` statement is processed separately for each item.
See :ref:`the_when_statement` for examples. See :ref:`the_when_statement` for examples.
Iterating over a dictionary Iterating over a dictionary
--------------------------- ---------------------------
To loop over a dict, use the ``dict2items`` :ref:`dict_filter`:: To loop over a dict, use the :ref:`dict2items <dict_filter>`:
.. code-block:: yaml
- name: create a tag dictionary of non-empty tags - name: create a tag dictionary of non-empty tags
set_fact: set_fact:
@ -268,14 +270,14 @@ There is also a specific lookup plugin ``inventory_hostnames`` that can be used
msg: "{{ item }}" msg: "{{ item }}"
loop: "{{ query('inventory_hostnames', 'all:!www') }}" loop: "{{ query('inventory_hostnames', 'all:!www') }}"
More information on the patterns can be found on :ref:`intro_patterns` More information on the patterns can be found in :ref:`intro_patterns`.
.. _query_vs_lookup: .. _query_vs_lookup:
Ensuring list input for ``loop``: ``query`` vs. ``lookup`` Ensuring list input for ``loop``: ``query`` vs. ``lookup``
========================================================== ==========================================================
The ``loop`` keyword requires a list as input, but the ``lookup`` keyword returns a string of comma-separated values by default. Ansible 2.5 introduced a new Jinja2 function named :ref:`query` that always returns a list, offering a simpler interface and more predictable output from lookup plugins when using the ``loop`` keyword. The ``loop`` keyword requires a list as input, but the ``lookup`` keyword returns a string of comma-separated values by default. Ansible 2.5 introduced a new Jinja2 function named :ref:`query <query>` that always returns a list, offering a simpler interface and more predictable output from lookup plugins when using the ``loop`` keyword.
You can force ``lookup`` to return a list to ``loop`` by using ``wantlist=True``, or you can use ``query`` instead. You can force ``lookup`` to return a list to ``loop`` by using ``wantlist=True``, or you can use ``query`` instead.