Skip to content

Commit b4594ca

Browse files
Code block languages: normalize casing of yaml and yaml+jinja, update list in style guide, add comments to keep lists in sync (#2848) (#2862)
* Update lists of allowed languages. * Stick to one casing of yaml and yaml+jinja. * Add comment to keep lists in sync. (cherry picked from commit 180ef73) Co-authored-by: Felix Fontein <[email protected]>
1 parent 710e0cf commit b4594ca

File tree

11 files changed

+46
-41
lines changed

11 files changed

+46
-41
lines changed

docs/docsite/rst/dev_guide/developing_plugins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ Here's a simple lookup plugin implementation --- this lookup returns the content
439439
440440
The following is an example of how this lookup is called:
441441

442-
.. code-block:: YAML
442+
.. code-block:: yaml
443443
444444
---
445445
- hosts: all

docs/docsite/rst/dev_guide/sidecar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Here is a longer example that shows documentation as embedded in a Python file:
5252
5353
This example shows the same documentation in YAML format:
5454

55-
.. code-block:: YAML
55+
.. code-block:: yaml
5656
5757
DOCUMENTATION:
5858
description: something

docs/docsite/rst/dev_guide/style_guide/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ The Ansible documentation allows the following values:
148148
* bash
149149
* console
150150
* csharp
151+
* diff
151152
* ini
153+
* jinja
152154
* json
155+
* md
153156
* powershell
154157
* python
155158
* rst
@@ -160,6 +163,9 @@ The Ansible documentation allows the following values:
160163
* yaml
161164
* yaml+jinja
162165

166+
..
167+
The above list is enforced by tests/checkers/rst-yamllint.py.
168+
163169
For example, you can highlight Python code using following syntax:
164170

165171
.. code-block:: rst

docs/docsite/rst/module_plugin_guide/plugin_filtering_config.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Rejecting modules
55

66
If you want to avoid using certain modules, you can add them to a reject list to prevent Ansible from loading them. To reject plugins, create a yaml configuration file. The default location for this file is :file:`/etc/ansible/plugin_filters.yml`. You can select a different path for the reject list using the :ref:`PLUGIN_FILTERS_CFG` setting in the ``defaults`` section of your ``ansible.cfg``. Here is an example reject list:
77

8-
.. code-block:: YAML
8+
.. code-block:: yaml
99
1010
---
1111
filter_version: '1.0'

docs/docsite/rst/playbook_guide/complex_data_manipulation.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The Python equivalent code would be:
5959
6060
There are several ways to do it in Ansible, this is just one example:
6161

62-
.. code-block:: YAML+Jinja
62+
.. code-block:: yaml+jinja
6363
:emphasize-lines: 4
6464
:caption: Way to extract matching keys from a list of dictionaries
6565

@@ -99,7 +99,7 @@ There are several ways to do it in Ansible, this is just one example:
9999
}
100100
101101
102-
.. code-block:: YAML+Jinja
102+
.. code-block:: yaml+jinja
103103
:caption: Get the unique list of values of a variable that vary per host
104104

105105
vars:
@@ -113,7 +113,7 @@ Find mount point
113113

114114
In this case, we want to find the mount point for a given path across our machines, since we already collect mount facts, we can use the following:
115115

116-
.. code-block:: YAML+Jinja
116+
.. code-block:: yaml+jinja
117117
:caption: Use selectattr to filter mounts into the list I can then sort and select the last from
118118
:emphasize-lines: 8
119119

@@ -133,7 +133,7 @@ Combine values from same list of dicts
133133
---------------------------------------
134134
Combining positive and negative filters from the examples above, you can get a 'value when it exists' and a 'fallback' when it doesn't.
135135

136-
.. code-block:: YAML+Jinja
136+
.. code-block:: yaml+jinja
137137
:caption: Use selectattr and rejectattr to get the ansible_host or inventory_hostname as needed
138138

139139
- hosts: localhost
@@ -155,7 +155,7 @@ Custom Fileglob Based on a Variable
155155

156156
This example uses `Python argument list unpacking <https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists>`_ to create a custom list of fileglobs based on a variable.
157157

158-
.. code-block:: YAML+Jinja
158+
.. code-block:: yaml+jinja
159159
:caption: Using fileglob with a list based on a variable.
160160

161161
- hosts: all
@@ -192,15 +192,15 @@ In most languages, it is easy to create a dictionary (also known as map/associat
192192

193193
These example produces ``{"a": "b", "c": "d"}``
194194

195-
.. code-block:: YAML+Jinja
195+
.. code-block:: yaml+jinja
196196
:caption: Simple list to dict by assuming the list is [key, value , key, value, ...]
197197

198198
vars:
199199
single_list: [ 'a', 'b', 'c', 'd' ]
200200
mydict: "{{ dict(single_list[::2] | zip_longest(single_list[1::2])) }}"
201201

202202

203-
.. code-block:: YAML+Jinja
203+
.. code-block:: yaml+jinja
204204
:caption: It is simpler when we have a list of pairs:
205205

206206
vars:
@@ -213,7 +213,7 @@ Both end up being the same thing, with ``zip_longest`` transforming ``single_lis
213213

214214
A bit more complex, using ``set_fact`` and a ``loop`` to create/update a dictionary with key value pairs from 2 lists:
215215

216-
.. code-block:: YAML+Jinja
216+
.. code-block:: yaml+jinja
217217
:caption: Using set_fact to create a dictionary from a set of lists
218218
:emphasize-lines: 3, 4
219219

@@ -236,7 +236,7 @@ This results in ``{"foo": "a", "var": "b", "bar": "c"}``.
236236

237237
You can even combine these simple examples with other filters and lookups to create a dictionary dynamically by matching patterns to variable names:
238238

239-
.. code-block:: YAML+Jinja
239+
.. code-block:: yaml+jinja
240240
:caption: Using 'vars' to define dictionary from a set of lists without needing a task
241241

242242
vars:
@@ -257,14 +257,14 @@ A quick explanation, since there is a lot to unpack from these two lines:
257257
An example of how to use facts to find a host's data that meets condition X:
258258

259259

260-
.. code-block:: YAML+Jinja
260+
.. code-block:: yaml+jinja
261261

262262
vars:
263263
uptime_of_host_most_recently_rebooted: "{{ansible_play_hosts_all | map('extract', hostvars, 'ansible_uptime_seconds') | sort | first}}"
264264

265265
An example to show a host uptime in days/hours/minutes/seconds (assuming facts were gathered).
266266

267-
.. code-block:: YAML+Jinja
267+
.. code-block:: yaml+jinja
268268

269269
- name: Show the uptime in days/hours/minutes/seconds
270270
ansible.builtin.debug:

docs/docsite/rst/playbook_guide/playbooks_blocks.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Grouping tasks with blocks
1414

1515
All tasks in a block inherit directives applied at the block level. Most of what you can apply to a single task (with the exception of loops) can be applied at the block level, so blocks make it much easier to set data or directives common to the tasks. The directive does not affect the block itself, it is only inherited by the tasks enclosed by a block. For example, a `when` statement is applied to the tasks within a block, not to the block itself.
1616

17-
.. code-block:: YAML
17+
.. code-block:: yaml
1818
:emphasize-lines: 3
1919
:caption: Block example with named tasks inside the block
2020
@@ -65,7 +65,7 @@ You can control how Ansible responds to task errors using blocks with ``rescue``
6565
Rescue blocks specify tasks to run when an earlier task in a block fails. This approach is similar to exception handling in many programming languages. Ansible only runs rescue blocks after a task returns a 'failed' state.
6666

6767
.. _block_rescue:
68-
.. code-block:: YAML
68+
.. code-block:: yaml
6969
:emphasize-lines: 3,14
7070
:caption: Block error handling example
7171
@@ -90,7 +90,7 @@ Rescue blocks specify tasks to run when an earlier task in a block fails. This a
9090
You can also add an ``always`` section to a block. Tasks in the ``always`` section run no matter what the task status of the previous block is.
9191

9292
.. _block_always:
93-
.. code-block:: YAML
93+
.. code-block:: yaml
9494
:emphasize-lines: 3,14
9595
:caption: Block with always section
9696
@@ -114,7 +114,7 @@ You can also add an ``always`` section to a block. Tasks in the ``always`` secti
114114
115115
Together, these elements offer complex error handling.
116116

117-
.. code-block:: YAML
117+
.. code-block:: yaml
118118
:emphasize-lines: 3,14,25
119119
:caption: Block with all sections
120120
@@ -153,7 +153,7 @@ If an error occurs in the block and the rescue task succeeds, Ansible reverts th
153153

154154
You can use blocks with ``flush_handlers`` in a rescue task to ensure that all handlers run even if an error occurs:
155155

156-
.. code-block:: YAML
156+
.. code-block:: yaml
157157
:emphasize-lines: 3,12
158158
:caption: Block run handlers in error handling
159159
@@ -189,7 +189,7 @@ ansible_failed_result
189189

190190
These can be inspected in the ``rescue`` section:
191191

192-
.. code-block:: YAML
192+
.. code-block:: yaml
193193
:emphasize-lines: 11,16
194194
:caption: Use special variables in rescue section.
195195

docs/docsite/rst/playbook_guide/playbooks_module_defaults.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you frequently call the same module with the same arguments, it can be useful
77

88
Here is a basic example:
99

10-
.. code-block:: YAML
10+
.. code-block:: yaml
1111
1212
- hosts: localhost
1313
module_defaults:
@@ -33,7 +33,7 @@ Here is a basic example:
3333
3434
The ``module_defaults`` keyword can be used at the play, block, and task level. Any module arguments explicitly specified in a task will override any established default for that module argument.
3535

36-
.. code-block:: YAML
36+
.. code-block:: yaml
3737
3838
- block:
3939
- name: Print a message
@@ -45,7 +45,7 @@ The ``module_defaults`` keyword can be used at the play, block, and task level.
4545
4646
You can remove any previously established defaults for a module by specifying an empty dict.
4747

48-
.. code-block:: YAML
48+
.. code-block:: yaml
4949
5050
- name: Create file1
5151
ansible.builtin.file:
@@ -61,7 +61,7 @@ Here are some more realistic use cases for this feature.
6161

6262
Interacting with an API that requires auth.
6363

64-
.. code-block:: YAML
64+
.. code-block:: yaml
6565
6666
- hosts: localhost
6767
module_defaults:
@@ -84,7 +84,7 @@ Interacting with an API that requires auth.
8484
8585
Setting a default AWS region for specific EC2-related modules.
8686

87-
.. code-block:: YAML
87+
.. code-block:: yaml
8888
8989
- hosts: localhost
9090
vars:
@@ -110,7 +110,7 @@ Module default groups allow to provide common parameters to groups of modules th
110110
Here is an example ``runtime.yml`` file for the ``ns.coll`` collection.
111111
This file defines an action group named ``ns.coll.my_group`` and places the ``sample_module`` from ``ns.coll`` and ``another_module`` from ``another.collection`` into the group.
112112

113-
.. code-block:: YAML
113+
.. code-block:: yaml
114114
115115
# collections/ansible_collections/ns/coll/meta/runtime.yml
116116
action_groups:
@@ -120,7 +120,7 @@ This file defines an action group named ``ns.coll.my_group`` and places the ``sa
120120
121121
This group can now be used in a playbook like this:
122122

123-
.. code-block:: YAML
123+
.. code-block:: yaml
124124
125125
- hosts: localhost
126126
module_defaults:
@@ -160,7 +160,7 @@ Use the groups with ``module_defaults`` by prefixing the group name with ``group
160160

161161
In a playbook, you can set module defaults for whole groups of modules, such as setting a common AWS region.
162162

163-
.. code-block:: YAML
163+
.. code-block:: yaml
164164
165165
# example_play.yml
166166
- hosts: localhost

docs/docsite/rst/plugins/filter.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ Using filter plugins
2323

2424
You can use filters anywhere you can use templating in Ansible: in a play, in variables file, or a Jinja2 template for the :ref:`template <template_module>` module. For more information on using filter plugins, see :ref:`playbooks_filters`. Filters can return any type of data, but if you want to always return a boolean, (``true`` or ``false``) you should be looking at a test instead.
2525

26-
.. code-block:: YAML+Jinja
26+
.. code-block:: yaml+jinja
2727

2828
vars:
2929
yaml_string: "{{ some_variable|to_yaml }}"
3030

3131
Filters are the preferred way to manipulate data in Ansible, you can identify a filter because it is normally preceded by a ``|``, with the expression on the left of it being the first input of the filter. Additional parameters may be passed into the filter itself as you would to most programming functions. These parameters can be either ``positional`` (passed in order) or ``named`` (passed as key=value pairs). When passing both types, positional arguments should go first.
3232

33-
.. code-block:: YAML+Jinja
33+
.. code-block:: yaml+jinja
3434

3535
passing_positional: "{{ (x == 32) | ternary('x is 32', 'x is not 32') }}"
3636
passing_extra_named_parameters: "{{ some_variable | to_yaml(indent=8, width=1337) }}"

docs/docsite/rst/plugins/lookup.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ Using lookup plugins
3434

3535
You can use lookup plugins anywhere you can use templating in Ansible: in a play, in variables file, or a Jinja2 template for the :ref:`template <template_module>` module. For more information on using lookup plugins, see :ref:`playbooks_lookups`.
3636

37-
.. code-block:: YAML+Jinja
37+
.. code-block:: yaml+jinja
3838

3939
vars:
4040
file_contents: "{{ lookup('file', 'path/to/file.txt') }}"
4141

4242
Lookups are an integral part of loops. Wherever you see ``with_``, the part after the underscore is the name of a lookup. For this reason, lookups are expected to output lists; for example, ``with_items`` uses the :ref:`items <items_lookup>` lookup:
4343

44-
.. code-block:: YAML+Jinja
44+
.. code-block:: yaml+jinja
4545

4646
tasks:
4747
- name: count to 3
@@ -50,7 +50,7 @@ Lookups are an integral part of loops. Wherever you see ``with_``, the part afte
5050

5151
You can combine lookups with :ref:`filters <playbooks_filters>`, :ref:`tests <playbooks_tests>` and even each other to do some complex data generation and manipulation. For example:
5252

53-
.. code-block:: YAML+Jinja
53+
.. code-block:: yaml+jinja
5454

5555
tasks:
5656
- name: Complicated chained lookups and filters
@@ -66,7 +66,7 @@ You can control how errors behave in all lookup plugins by setting ``errors`` to
6666

6767
To ignore lookup errors:
6868

69-
.. code-block:: YAML+Jinja
69+
.. code-block:: yaml+jinja
7070

7171
- name: if this file does not exist, I do not care .. file plugin itself warns anyway ...
7272
debug: msg="{{ lookup('file', '/nosuchfile', errors='ignore') }}"
@@ -82,7 +82,7 @@ To ignore lookup errors:
8282
8383
To get a warning instead of a failure:
8484

85-
.. code-block:: YAML+Jinja
85+
.. code-block:: yaml+jinja
8686

8787
- name: if this file does not exist, let me know, but continue
8888
debug: msg="{{ lookup('file', '/nosuchfile', errors='warn') }}"
@@ -100,7 +100,7 @@ To get a warning instead of a failure:
100100
101101
To get a fatal error (the default):
102102

103-
.. code-block:: YAML+Jinja
103+
.. code-block:: yaml+jinja
104104

105105
- name: if this file does not exist, FAIL (this is the default)
106106
debug: msg="{{ lookup('file', '/nosuchfile', errors='strict') }}"

docs/docsite/rst/plugins/test.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Tests always return ``True`` or ``False``, they are always a boolean, if you nee
2929

3030
You can recognize test plugins by the use of the ``is`` statement in a template, they can also be used as part of the ``select`` family of filters.
3131

32-
.. code-block:: YAML+Jinja
32+
.. code-block:: yaml+jinja
3333

3434
vars:
3535
is_ready: '{{ task_result is success }}'
@@ -41,7 +41,7 @@ You can recognize test plugins by the use of the ``is`` statement in a template,
4141

4242
Tests will always have an ``_input`` and this is normally what is on the left side of ``is``. Tests can also take additional parameters as you would to most programming functions. These parameters can be either ``positional`` (passed in order) or ``named`` (passed as key=value pairs). When passing both types, positional arguments should go first.
4343

44-
.. code-block:: YAML+Jinja
44+
.. code-block:: yaml+jinja
4545

4646
tasks:
4747
- name: pass a positional parameter to match test
@@ -62,7 +62,7 @@ Using test plugins with lists
6262

6363
As mentioned above, one way to use tests is with the ``select`` family of filters (``select``, ``reject``, ``selectattr``, ``rejectattr``).
6464

65-
.. code-block:: YAML+Jinja
65+
.. code-block:: yaml+jinja
6666

6767
# give me only defined variables from a list of variables, using 'defined' test
6868
good_vars: "{{ all_vars|select('defined') }}"

0 commit comments

Comments
 (0)