That certainly works, but if you are trying to package up a blueprint and have everything self-contained for the user to turn on, my way works better.
I dont know why no one is telling you this, but you can actually use global variables in jinja by explicitly defining the scope:
{%- set g = namespace(test_var = 1) %}
{{ g.test_var }}
{% some for loop %}
{% set g.test_var = g.test_var + 1 %}
{% endfor %}
{{ g.test_var }}
And that’s not the scope issues that OP was running into. namespace
only solves scoping issues inside a single template. OP was attempting to use variables defined in action sections that were not in scope of the action section they were in.