Skip to content

Commit 37af393

Browse files
committed
Add reset-previous-blocks meta action.
1 parent d65d102 commit 37af393

File tree

7 files changed

+418
-103
lines changed

7 files changed

+418
-103
lines changed

changelogs/fragments/409-meta.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- "Add ``ansible-output-meta`` directive that allows to apply meta actions, like resetting previous code blocks for variable references (https://github.com/ansible-community/antsibull-docs/pull/409)."

docs/ansible-output.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,63 @@ The task produces the following output:
183183
}
184184
```
185185

186+
## Controlling code block contexts
187+
188+
Next to the `ansible-output-data` RST directive, antsibull-docs also provides a `ansible-output-meta` RST directive.
189+
This meta directive allows to apply actions to the context for the next `ansible-output-data` directives.
190+
191+
### Reset previous code blocks
192+
193+
The `reset-previous-blocks` action resets the list of previous code blocks.
194+
It can be used as follows:
195+
```rst
196+
.. ansible-output-meta::
197+
198+
actions:
199+
- name: reset-previous-blocks
200+
```
201+
202+
This is relevant when using `previous_code_block` variables where you specify `previous_code_block_index`.
203+
If you want several consecutive `ansible-output-data` directives to reference the same code block,
204+
you can reset the previous blocks directly before that code block,
205+
and then reference that code block as the one with index `0`:
206+
```rst
207+
(more text with other code blocks)
208+
209+
.. ansible-output-meta::
210+
211+
actions:
212+
- name: reset-previous-blocks
213+
214+
.. code-block:: yaml
215+
216+
# This code block now has index 0, no matter how many other code blocks
217+
# came before the above action.
218+
foo: bar
219+
220+
Now you can have multiple ansible-output-data directives referencing the
221+
above ``yaml`` block as the ``yaml`` block with index 0:
222+
223+
.. ansible-output-data::
224+
225+
variables:
226+
content:
227+
previous_code_block: yaml
228+
previous_code_block_index: 0
229+
playbook: |-
230+
- hosts: localhost
231+
tasks:
232+
- ansible.builtin.debug:
233+
msg: "{{ data }}"
234+
vars:
235+
data:
236+
@{{ content | indent(10) }}@
237+
238+
.. code-block:: ansible-output
239+
240+
...
241+
```
242+
186243
## Post-processing ansible-playbook output
187244

188245
Out of the box, you can post-process the `ansible-playbook` output in some ways:

0 commit comments

Comments
 (0)