Skip to content

Commit 6a3a90c

Browse files
authored
Fix a few examples in docs that are not 2.19 compatible (#2581)
* Fix a few examples in docs that are not 2.19 compatible * remove finalize example of None -> empty string * A few assert cleanups
1 parent b21e9c7 commit 6a3a90c

File tree

5 files changed

+5
-93
lines changed

5 files changed

+5
-93
lines changed

docs/docsite/rst/network/dev_guide/developing_resource_modules_network.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ The following example walks through the integration tests for the ``vyos.vyos.vy
582582
- name: Assert that before dicts were correctly generated
583583
assert:
584584
that:
585-
- "{{ populate | symmetric_difference(result['before']) | length == 0 }}"
585+
- populate | symmetric_difference(result['before']) | length == 0
586586
- name: Assert that correct commands were generated
587587
assert:
588588
that:
@@ -594,8 +594,7 @@ The following example walks through the integration tests for the ``vyos.vyos.vy
594594
- name: Assert that after dicts were correctly generated
595595
assert:
596596
that:
597-
- "{{ overridden['after'] | symmetric_difference(result['after'])
598-
| length == 0 }}"
597+
- overridden['after'] | symmetric_difference(result['after']) | length == 0
599598
- name: Override device configuration with provided configuration (IDEMPOTENT)
600599
register: result
601600
vyos.vyos.vyos_l3_interfaces:
@@ -614,8 +613,7 @@ The following example walks through the integration tests for the ``vyos.vyos.vy
614613
- name: Assert that before dicts were correctly generated
615614
assert:
616615
that:
617-
- "{{ overridden['after'] | symmetric_difference(result['before'])
618-
| length == 0 }}"
616+
- overridden['after'] | symmetric_difference(result['before']) | length == 0
619617
always:
620618
- import_tasks: _remove_config.yaml
621619

docs/docsite/rst/playbook_guide/complex_data_manipulation.rst

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,44 +127,6 @@ In this case, we want to find the mount point for a given path across our machin
127127
msg: "{{(ansible_facts.mounts | selectattr('mount', 'in', path) | list | sort(attribute='mount'))[-1]['mount']}}"
128128

129129

130-
.. _omit_elements_from_list:
131-
132-
Omit elements from a list
133-
-------------------------
134-
135-
The special ``omit`` variable ONLY works with module options, but we can still use it in other ways as an identifier to tailor a list of elements:
136-
137-
.. code-block:: YAML+Jinja
138-
:caption: Inline list filtering when feeding a module option
139-
:emphasize-lines: 3, 6
140-
141-
- name: Enable a list of Windows features, by name
142-
ansible.builtin.set_fact:
143-
win_feature_list: "{{ namestuff | reject('equalto', omit) | list }}"
144-
vars:
145-
namestuff:
146-
- "{{ (fs_installed_smb_v1 | default(False)) | ternary(omit, 'FS-SMB1') }}"
147-
- "foo"
148-
- "bar"
149-
150-
151-
Another way is to avoid adding elements to the list in the first place, so you can just use it directly:
152-
153-
.. code-block:: YAML+Jinja
154-
:caption: Using set_fact in a loop to increment a list conditionally
155-
:emphasize-lines: 3, 4, 6
156-
157-
- name: Build unique list with some items conditionally omitted
158-
ansible.builtin.set_fact:
159-
namestuff: ' {{ (namestuff | default([])) | union([item]) }}'
160-
when: item != omit
161-
loop:
162-
- "{{ (fs_installed_smb_v1 | default(False)) | ternary(omit, 'FS-SMB1') }}"
163-
- "foo"
164-
- "bar"
165-
166-
167-
168130
.. _combine_optional_values:
169131

170132
Combine values from same list of dicts

docs/docsite/rst/playbook_guide/playbooks_async.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ If you need a synchronization point with an async task, you can register it to o
122122
async_status:
123123
jid: "{{ yum_sleeper.ansible_job_id }}"
124124
register: job_result
125-
until: job_result.finished
125+
until: job_result is finished
126126
retries: 100
127127
delay: 10
128128

@@ -174,7 +174,7 @@ To run multiple asynchronous tasks while limiting the number of tasks running co
174174
loop_control:
175175
loop_var: "async_result_item"
176176
register: async_poll_results
177-
until: async_poll_results.finished
177+
until: async_poll_results is finished
178178
retries: 30
179179

180180
.. seealso::

docs/docsite/rst/playbook_guide/playbooks_filters.rst

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,28 +1863,6 @@ To search in a string or extract parts of a string with a regular expression, us
18631863
{{ '21/42' | regex_search('(?P<dividend>[0-9]+)/(?P<divisor>[0-9]+)', '\\g<dividend>', '\\g<divisor>') }}
18641864
# => ['21', '42']
18651865
1866-
The :ansplugin:`ansible.builtin.regex_search#filter` filter returns an empty string if it cannot find a match:
1867-
1868-
.. code-block:: jinja
1869-
1870-
{{ 'ansible' | regex_search('foobar') }}
1871-
# => ''
1872-
1873-
1874-
.. note::
1875-
1876-
1877-
The :ansplugin:`ansible.builtin.regex_search#filter` filter returns ``None`` when used in a Jinja expression (for example in conjunction with operators, other filters, and so on). See the two examples below.
1878-
1879-
.. code-block:: jinja
1880-
1881-
{{ 'ansible' | regex_search('foobar') == '' }}
1882-
# => False
1883-
{{ 'ansible' | regex_search('foobar') is none }}
1884-
# => True
1885-
1886-
This is due to historic behavior and the custom re-implementation of some of the Jinja internals in Ansible. Enable the ``jinja2_native`` setting if you want the :ansplugin:`ansible.builtin.regex_search#filter` filter to always return ``None`` if it cannot find a match. See :ref:`jinja2_faqs` for details.
1887-
18881866
To extract all occurrences of regex matches in a string, use the :ansplugin:`ansible.builtin.regex_findall#filter` filter:
18891867

18901868
.. code-block:: jinja

docs/docsite/rst/reference_appendices/faq.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -898,32 +898,6 @@ and backups, which most file based modules also support:
898898
state: absent
899899
when: updated is changed
900900
901-
.. _jinja2_faqs:
902-
903-
Why does the ``regex_search`` filter return `None` instead of an empty string?
904-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
905-
906-
Until the jinja2 2.10 release, Jinja was only able to return strings, but Ansible needed Python objects in some cases. Ansible uses ``safe_eval`` and only sends strings that look like certain types of Python objects through this function. With ``regex_search`` that does not find a match, the result (``None``) is converted to the string "None" which is not useful in non-native jinja2.
907-
908-
The following example of a single templating action shows this behavior:
909-
910-
.. code-block:: jinja
911-
912-
{{ 'ansible' | regex_search('foobar') }}
913-
914-
This example does not result in a Python ``None``, so Ansible historically converted it to "" (empty string).
915-
916-
The native jinja2 functionality actually allows us to return full Python objects, that are always represented as Python objects everywhere, and as such the result of a single templating action with ``regex_search`` can result in the Python ``None``.
917-
918-
.. note::
919-
920-
Native jinja2 functionality is not needed when ``regex_search`` is used as an intermediate result that is then compared to the jinja2 ``none`` test.
921-
922-
.. code-block:: jinja
923-
924-
{{ 'ansible' | regex_search('foobar') is none }}
925-
926-
927901
.. _docs_contributions:
928902

929903
How do I submit a change to the documentation?

0 commit comments

Comments
 (0)