@@ -183,6 +183,63 @@ The task produces the following output:
183
183
}
184
184
```
185
185
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
+
186
243
## Post-processing ansible-playbook output
187
244
188
245
Out of the box, you can post-process the ` ansible-playbook ` output in some ways:
0 commit comments