Skip to content

Commit c047609

Browse files
authored
Avoid all literal blocks without explicitly set language (#2807)
* Avoid code-blocks without language. * Adjust checker to catch such code blocks as well.
1 parent 0408da3 commit c047609

File tree

11 files changed

+129
-45
lines changed

11 files changed

+129
-45
lines changed

docs/docsite/rst/dev_guide/style_guide/grammar_punctuation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ A pair of em dashes can replace a pair of parentheses. Dashes are considered les
7777
.. note::
7878
When dashes are used in place of parentheses, surrounding punctuation should be omitted. Compare the following examples.
7979

80-
::
80+
.. code-block:: text
8181
8282
Upon discovering the errors (all 124 of them), the publisher immediately recalled the books.
8383
@@ -86,7 +86,7 @@ A pair of em dashes can replace a pair of parentheses. Dashes are considered les
8686
8787
When used in place of parentheses at the end of a sentence, only a single dash is used.
8888

89-
::
89+
.. code-block:: text
9090
9191
After three weeks on set, the cast was fed up with his direction (or, rather, lack of direction).
9292
@@ -114,7 +114,7 @@ The hyphen's primary function is the formation of certain compound terms. Do not
114114

115115
Use hyphens to avoid ambiguity or confusion:
116116

117-
::
117+
.. code-block:: text
118118
119119
a little-used car
120120
a little used-car

docs/docsite/rst/playbook_guide/playbooks_loops.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ Variable Description
456456
``ansible_loop.nextitem`` The item from the following iteration of the loop. Undefined during the last iteration.
457457
========================== ===========
458458

459-
::
459+
.. code-block:: yaml
460460
461461
loop_control:
462462
extended: true
@@ -467,7 +467,7 @@ Variable Description
467467

468468
To disable the ``ansible_loop.allitems`` item, to reduce memory consumption, set ``loop_control.extended_allitems: false``.
469469

470-
::
470+
.. code-block:: yaml
471471
472472
loop_control:
473473
extended: true

docs/docsite/rst/porting_guides/porting_guide_2.0.rst

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,24 @@ This section discusses any changes you may need to make to your playbooks.
4343
4444
"msg": "test1 1\\3"
4545
46-
To make an escaped string that will work on all versions you have two options::
46+
To make an escaped string that will work on all versions you have two options:
4747

48-
- debug: msg="{{ 'test1_junk 1\\3' | regex_replace('(.*)_junk (.*)', '\\1 \\2') }}"
48+
.. code-block:: yaml+jinja
4949

50-
uses key=value escaping which has not changed. The other option is to check for the ansible version::
50+
- debug: msg="{{ 'test1_junk 1\\3' | regex_replace('(.*)_junk (.*)', '\\1 \\2') }}"
5151

52-
"{{ (ansible_version|version_compare('2.0', 'ge'))|ternary( 'test1_junk 1\\3' | regex_replace('(.*)_junk (.*)', '\\1 \\2') , 'test1_junk 1\\\\3' | regex_replace('(.*)_junk (.*)', '\\\\1 \\\\2') ) }}"
52+
uses key=value escaping which has not changed. The other option is to check for the ansible version:
53+
54+
.. code-block:: jinja
55+
56+
"{{ (ansible_version|version_compare('2.0', 'ge'))|ternary( 'test1_junk 1\\3' | regex_replace('(.*)_junk (.*)', '\\1 \\2') , 'test1_junk 1\\\\3' | regex_replace('(.*)_junk (.*)', '\\\\1 \\\\2') ) }}"
5357
5458
* trailing newline When a string with a trailing newline was specified in the
5559
playbook through yaml dict format, the trailing newline was stripped. When
5660
specified in key=value format, the trailing newlines were kept. In v2, both
5761
methods of specifying the string will keep the trailing newlines. If you
5862
relied on the trailing newline being stripped, you can change your playbook
59-
using the following as an example::
63+
using the following as an example:
6064

6165

6266
* Syntax in 1.9.x
@@ -168,17 +172,23 @@ Example of a recommended variant:
168172
* Ranges specified in host patterns should use the [x:y] syntax, instead of [x-y].
169173
* Playbooks using privilege escalation should always use "become*" options rather than the old su*/sudo* options.
170174
* The "short form" for vars_prompt is no longer supported.
171-
For example::
175+
For example:
176+
177+
.. code-block:: yaml+jinja
172178

173179
vars_prompt:
174180
variable_name: "Prompt string"
175181

176-
* Specifying variables at the top level of a task include statement is no longer supported. For example::
182+
* Specifying variables at the top level of a task include statement is no longer supported. For example:
183+
184+
.. code-block:: yaml+jinja
177185

178186
- include_tasks: foo.yml
179-
a: 1
187+
a: 1
188+
189+
Should now be:
180190

181-
Should now be::
191+
.. code-block:: yaml+jinja
182192

183193
- include_tasks: foo.yml
184194
vars:
@@ -187,11 +197,15 @@ Should now be::
187197
* Setting any_errors_fatal on a task is no longer supported. This should be set at the play level only.
188198
* Bare variables in the `environment` dictionary (for plays/tasks/and so on) are no longer supported. Variables specified there should use the full variable syntax: '{{foo}}'.
189199
* Tags (or any directive) should no longer be specified with other parameters in a task include. Instead, they should be specified as an option on the task.
190-
For example::
200+
For example:
201+
202+
.. code-block:: yaml+jinja
191203

192204
- include_tasks: foo.yml tags=a,b,c
193205

194-
Should be::
206+
Should be:
207+
208+
.. code-block:: yaml+jinja
195209

196210
- include_tasks: foo.yml
197211
tags: [a, b, c]
@@ -204,31 +218,41 @@ Other caveats
204218

205219
Here are some corner cases encountered when updating. These are mostly caused by the more stringent parser validation and the capture of errors that were previously ignored.
206220

207-
* Bad variable composition::
221+
* Bad variable composition:
222+
223+
.. code-block:: yaml+jinja
208224

209225
with_items: myvar_{{rest_of_name}}
210226

211-
This worked 'by accident' as the errors were retemplated and ended up resolving the variable, it was never intended as valid syntax and now properly returns an error, use the following instead.::
227+
This worked 'by accident' as the errors were retemplated and ended up resolving the variable, it was never intended as valid syntax and now properly returns an error, use the following instead.:
228+
229+
.. code-block:: jinja
212230
213231
hostvars[inventory_hostname]['myvar_' + rest_of_name]
214232
215-
* Misspelled directives::
233+
* Misspelled directives:
234+
235+
.. code-block:: yaml+jinja
216236

217237
- task: dostuf
218238
becom: yes
219239

220240
The task always ran without using privilege escalation (for that you need `become`) but was also silently ignored so the play 'ran' even though it should not, now this is a parsing error.
221241

222242

223-
* Duplicate directives::
243+
* Duplicate directives:
244+
245+
.. code-block:: yaml+jinja
224246

225247
- task: dostuf
226248
when: True
227249
when: False
228250

229251
The first `when` was ignored and only the 2nd one was used as the play ran w/o warning it was ignoring one of the directives, now this produces a parsing error.
230252

231-
* Conflating variables and directives::
253+
* Conflating variables and directives:
254+
255+
.. code-block:: yaml+jinja
232256

233257
- role: {name=rosy, port=435 }
234258

@@ -239,12 +263,16 @@ Here are some corner cases encountered when updating. These are mostly caused by
239263
later in the play, this created issues if a host tried to reconnect or was using a non caching connection. Now it will be correctly identified as a directive and the `port` variable
240264
will appear as undefined, this now forces the use of non conflicting names and removes ambiguity when adding settings and variables to a role invocation.
241265

242-
* Bare operations on `with_`::
266+
* Bare operations on `with_`:
267+
268+
.. code-block:: yaml+jinja
243269

244270
with_items: var1 + var2
245271

246272
An issue with the 'bare variable' features, which was supposed only template a single variable without the need of braces ({{ )}}, would in some versions of Ansible template full expressions.
247-
Now you need to use proper templating and braces for all expressions everywhere except conditionals (`when`)::
273+
Now you need to use proper templating and braces for all expressions everywhere except conditionals (`when`):
274+
275+
.. code-block:: yaml+jinja
248276

249277
with_items: "{{var1 + var2}}"
250278

docs/docsite/rst/porting_guides/porting_guide_2.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ netbox.netbox
576576
the decision to change the method to convert to an integer for the NetBox
577577
API.
578578

579-
::
579+
.. code-block:: yaml+jinja
580580

581581
tasks:
582582
- name: Create device within NetBox with only required information

docs/docsite/rst/porting_guides/porting_guide_2.4.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ automatically. In 2.4, users are responsible for escaping backslashes themselves
152152
brings the template lookup plugin inline with the template module so that the same backslash
153153
escaping rules apply to both.
154154

155-
If you have a template lookup like this::
155+
If you have a template lookup like this:
156+
157+
.. code-block:: yaml+jinja
156158

157159
- debug:
158160
msg: '{{ lookup("template", "template.j2") }}'
@@ -175,7 +177,9 @@ Tests
175177
Tests succeeded/failed
176178
-----------------------
177179

178-
Prior to Ansible version 2.4, a task return code of ``rc`` would override a return code of ``failed``. In version 2.4, both ``rc`` and ``failed`` are used to calculate the state of the task. Because of this, test plugins ``succeeded``/``failed``` have also been changed. This means that overriding a task failure with ``failed_when: no`` will result in ``succeeded``/``failed`` returning ``True``/``False``. For example::
180+
Prior to Ansible version 2.4, a task return code of ``rc`` would override a return code of ``failed``. In version 2.4, both ``rc`` and ``failed`` are used to calculate the state of the task. Because of this, test plugins ``succeeded``/``failed``` have also been changed. This means that overriding a task failure with ``failed_when: no`` will result in ``succeeded``/``failed`` returning ``True``/``False``. For example:
181+
182+
.. code-block:: yaml+jinja
179183

180184
- command: /bin/false
181185
register: result

docs/docsite/rst/porting_guides/porting_guide_2.5.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ The relevant change in those examples is, that in Ansible 2.5, the included file
7878
Fixed handling of keywords and inline variables
7979
-----------------------------------------------
8080

81-
We made several fixes to how we handle keywords and 'inline variables', to avoid conflating the two. Unfortunately these changes mean you must specify whether `name` is a keyword or a variable when calling roles. If you have playbooks that look like this::
81+
We made several fixes to how we handle keywords and 'inline variables', to avoid conflating the two. Unfortunately these changes mean you must specify whether `name` is a keyword or a variable when calling roles. If you have playbooks that look like this:
82+
83+
.. code-block:: yaml+jinja
8284

8385
roles:
8486
- { role: myrole, name: Justin, othervar: othervalue, become: True}
8587

86-
You will run into errors because Ansible reads name in this context as a keyword. Beginning in 2.5, if you want to use a variable name that is also a keyword, you must explicitly declare it as a variable for the role::
88+
You will run into errors because Ansible reads name in this context as a keyword. Beginning in 2.5, if you want to use a variable name that is also a keyword, you must explicitly declare it as a variable for the role:
89+
90+
.. code-block:: yaml+jinja
8791

8892
roles:
8993
- { role: myrole, vars: {name: Justin, othervar: othervalue}, become: True}

docs/docsite/rst/porting_guides/porting_guide_2.6.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ Noteworthy module changes
5656
* The :ref:`file_module` now emits a deprecation warning when ``src`` is specified with a state
5757
other than ``hard`` or ``link`` as it is only supposed to be useful with those. This could have
5858
an effect on people who were depending on a buggy interaction between src and other state's to
59-
place files into a subdirectory. For example::
59+
place files into a subdirectory. For example:
60+
61+
.. code-block:: console
6062
6163
$ ansible localhost -m file -a 'path=/var/lib src=/tmp/ state=directory'
6264
6365
Would create a directory named ``/tmp/lib``. Instead of the above, simply spell out the entire
64-
destination path like this::
66+
destination path like this:
67+
68+
.. code-block:: console
6569
6670
$ ansible localhost -m file -a 'path=/tmp/lib state=directory'
6771

docs/docsite/rst/porting_guides/porting_guide_2.7.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ Noteworthy module changes
217217
* The ``win_disk_image`` module has deprecated the return value ``mount_path``, use ``mount_paths[0]`` instead. This will
218218
be removed in Ansible 2.11.
219219

220-
* ``include_role`` and ``include_tasks`` can now be used directly from ``ansible`` (adhoc) and ``ansible-console``::
220+
* ``include_role`` and ``include_tasks`` can now be used directly from ``ansible`` (adhoc) and ``ansible-console``:
221+
222+
.. code-block:: console
221223
222224
#> ansible -m include_role -a 'name=myrole' all
223225

docs/docsite/rst/porting_guides/porting_guide_2.8.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,21 @@ Jinja Undefined values
4444
Beginning in version 2.8, attempting to access an attribute of an Undefined value in Jinja will return another Undefined value, rather than throwing an error immediately. This means that you can now simply use
4545
a default with a value in a nested data structure when you don't know if the intermediate values are defined.
4646

47-
In Ansible 2.8::
47+
In Ansible 2.8:
48+
49+
.. code-block:: jinja
4850
4951
{{ foo.bar.baz | default('DEFAULT') }}
5052
51-
In Ansible 2.7 and older::
53+
In Ansible 2.7 and older:
54+
55+
.. code-block:: jinja
5256
5357
{{ ((foo | default({})).bar | default({})).baz | default('DEFAULT') }}
5458
55-
or::
59+
or:
60+
61+
.. code-block:: jinja
5662
5763
{{ foo.bar.baz if (foo is defined and foo.bar is defined and foo.bar.baz is defined) else 'DEFAULT' }}
5864
@@ -309,14 +315,18 @@ Become Prompting
309315

310316
Beginning in version 2.8, by default Ansible will use the word ``BECOME`` to prompt you for a password for elevated privileges (``sudo`` privileges on Unix systems or ``enable`` mode on network devices):
311317

312-
By default in Ansible 2.8::
318+
By default in Ansible 2.8:
319+
320+
.. code-block:: console
313321
314322
ansible-playbook --become --ask-become-pass site.yml
315323
BECOME password:
316324
317325
If you want the prompt to display the specific ``become_method`` you're using, instead of the general value ``BECOME``, set :ref:`AGNOSTIC_BECOME_PROMPT` to ``False`` in your Ansible configuration.
318326

319-
By default in Ansible 2.7, or with ``AGNOSTIC_BECOME_PROMPT=False`` in Ansible 2.8::
327+
By default in Ansible 2.7, or with ``AGNOSTIC_BECOME_PROMPT=False`` in Ansible 2.8:
328+
329+
.. code-block:: console
320330
321331
ansible-playbook --become --ask-become-pass site.yml
322332
SUDO password:
@@ -325,7 +335,9 @@ Deprecated
325335
==========
326336

327337
* Setting the async directory using ``ANSIBLE_ASYNC_DIR`` as an task/play environment key is deprecated and will be
328-
removed in Ansible 2.12. You can achieve the same result by setting ``ansible_async_dir`` as a variable like::
338+
removed in Ansible 2.12. You can achieve the same result by setting ``ansible_async_dir`` as a variable like:
339+
340+
.. code-block:: yaml+jinja
329341

330342
- name: run task with custom async directory
331343
command: sleep 5

0 commit comments

Comments
 (0)