I'd like to find all variables with the myvar_ prefix and make a shell script that uses their names and contents.
---
- set_fact:
myvar_a: "a"
myvar_b: "b"
myvar_c: "c"
- name: Format Django webapp parameters
shell: |
truncate -s0 out.txt
{% for param in lookup('ansible.builtin.varnames', '^myvar_.+') %}
echo {{ param }} >> out.txt
{% endfor %}
The output is:
m
y
v
a
r
_
a
,
m
y
v
a
r
_
b
,
m
y
v
a
r
_
c
It iterates a string character by character for some reason.
How to get variable names into out.txt?
How to get the contents of these variables to out.txt? (ok, it'll be {{ lookup("vars", param) }})