On Wednesday, October 28, 2015 15:07:45 James Cammarata wrote:
> Registered variables are stored on a per-host basis, and thus are always
> visible to the host when it's compiling its variables. So it's not really a
> scoping problem, as it's not tied to the include. Now, if you passed the
> variable in as a parameter to the include, it would in fact limit the scope
> to that include.
OK, that makes sense. First part of the confusion came because I didn't
realize Ansible eval'ed the 'when' condition for each step of the include.
Probably didn't remember reading that in the docs.
As for the scoping, to be sure I'm understanding:
The "outer" file creates a var called 'st' and uses it in the 'when' to include
<file>.
<file> has a step which registers its result in 'st' (and changes the value in
this case).
The outer file then re-evaluates the 'st' var (which is the *same* var), sees
the condition is no longer true, and skips the rest of the steps.
That's actually kind of handy...the included file could short-circuit its own
execution if it changed the value of the var used in the 'when'.
Much thanks to you and Brian for your patience in walking me through this!