From 6ca723c74e049039931b11cb130f6c453a16ef7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 17 Sep 2022 10:30:37 +0200 Subject: [PATCH] Doc update regarding variables' behavior --- README.md | 5 ++--- inventory_plugins/reconstructed.py | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f744298..ca1b399 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,8 @@ containing the list of instructions which are part of the block. It may have a `rescue` field, containing a list of instructions which will be executed on error, and `always`, which may contain a list of instructions to execute in all cases. If the `locals` field is defined, it must contain a table of local -variables to define. Any local variable defined by the instructions under -`block`, `rescue` or `always` will go out of scope once the block finishes -executing. +variables to define. If these variables already exist, their state will be +saved and they will be restored after the block is done executing. A somewhat silly example can be found in the `example` directory. Trying to execute it using `ansible-inventory --graph` results in the following output. diff --git a/inventory_plugins/reconstructed.py b/inventory_plugins/reconstructed.py index 357cbc4..bb500c3 100644 --- a/inventory_plugins/reconstructed.py +++ b/inventory_plugins/reconstructed.py @@ -35,7 +35,8 @@ DOCUMENTATION = """ template that will return a list). The instruction will be repeated for each value in the list. The C(loop_var) field may be added to specify the name of the variable into which the current value will - be written; by default the C(item) variable will be used. + be written; by default the C(item) variable will be used. Once the + loop execution ends, the loop variable's previous state is restored. - The C(when) field, if present, must contain a Jinja expression representing a condition which will be checked before the instruction is executed. @@ -49,7 +50,8 @@ DOCUMENTATION = """ of instructions to execute in all cases. If the C(locals) field is defined, it must contain a table of local variables to define. Any local variable defined by the instructions under C(block), C(rescue) - or C(always) will go out of scope once the block finishes executing. + or C(always) will go out of scope once the block finishes executing, + and the previous values, if any, will be restored. - C(create_group) creates a group. The name of the group must be provided using the C(group) field, which must be a valid name or a Jinja template that evaluates to a valid name. In addition, a