I have a shell script that I’m trying to convert to Ansible. It currently is similar to the following:
for uid in {1000…6500}
user = ipa user-find --uid=$uid --raw |grep uid: | awk ‘{print $2}’
echo “user,uid” >> uid.csv
do
How do I accomplish this in Ansible? I know I can use the shell module with a loop similar to the following:
name: Get user name based on the UID
shell: “set -o pipefail && /bin/ipa user-find --uid={{ uid }} --raw | grep uid: | awk ‘{print $2}’”
register: output
loop: {{ range(1000, 6500, 1) | list }}
But how can I have each iteration add the values I need to a file? I know that I can use lineinfile, but I need to have it do this for each iteration of the loop.
for uid in {1000..6500}
user = ipa user-find --uid=$uid --raw |grep uid: | awk '{print $2}'
echo "user,uid" >> uid.csv
do
This is the Ansible equivalent, I think.
The module "getent" creates the dictionary "getent_passwd". Next "set_fact"
creates the list of dictionaries with attributes "user" and "uid" only. Next
"set_fact" selects required "uid" and module "template" writes the file.
OK, I’m finally getting back to this. I failed to mention that I’m trying to query our LDAP server, which is Red Hat IDM (based off of FreeIPA). Here’s what I have so far but its not working: