I'm trying to dynamically create a template from a list and I'm wondering if Ansible supports something like
{% for server in [sg-bend1, sg-bend2] %}
check program {{ server }}_test
with path /home/ubuntu/t.sh {{ server }}
if status != 0 then alert
{% endfor %}
theoretically this should produce
check program sg-bend1_test
with path /home/ubuntu/t.sh sg-bend1
if status != 0 then alert
check program sg-bend2_test
with path /home/ubuntu/t.sh sg-bend2
if status != 0 then alert
According the provided description I understand your question is related to Jinja2 Templating and syntax only.
One approach you could try is the following
Similar Q&A
Documentation
As far as I understand the documentation the solution should be to provide the list in a variable
or an other syntax
Example
will result into an output of