I have a playbook that will use the user_find API call against our FreeIPA server to retrieve a list of all users. What I’m trying to do is get the total count, then use that count in my j2 file. I’m getting the count as follows:
-
name: Set IDM facts
set_fact:
idmcount: “{{ userfind.json.result.count|int }}” -
name: Output data
template:
src: uid.csv.j2
dest: uid.csv
In my j2 file, I’ve tried 2 different things:
Option 1:
{% for i in idmcount %}
{{ i }}
{% endfor %}
This prints the count as strings (the value is 1740):
1
7
4
0
Option 2:
{% for i in {{ idmcount }} %}
{{ i }}
{% endfor %}
This gives me the following error:
fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “AnsibleError: template error while templating string: expected token ‘:’, got ‘}’. String: {% for i in {{ idmcount }} %}\n{{ i }}\n{% endfor %}\n”}
So how do I use that count as a loop control variable?
Thanks,
Harry