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:

---
- hosts: ldap
  gather_facts: no
  become: yes
  become_method: sudo

  tasks:

   - name: Obtain Kerberos Ticket on Tower
     command: /usr/bin/kinit admin@ldap -k -t /var/lib/awx/admin.keytab
     delegate_to: tower_server

   - name: Obtain Kerberos Ticket from LDAP
     command: /usr/bin/kinit admin@ldap -k -t /root/admin.keytab

   - name: Get password entries from getent
     getent:
       database: password

   - name: Set User facts
     set_fact:
       uid_list: "{{ getent_passwd | dict2items | json_query('[].{user:key, 
uid: to_number(value[1])}) }}"

   - name: Set Attribute facts
     set_fact:
       uid_list: "{{ uid_list | json_query('[?uid >= `1000`]) | 
json_query('[?uid <= `1010`]') | sort(attribute='uid') | list }}"

   - name: Add to CSV template
     template:
       src: uid.csv.j2
       dest: uid.csv

Template:

User ID Inventory (generated on $[(datetime.datetime.today().date())]
{% for item in uid_list %}
{{ item.user }},{{ item.uid }}
{% endfor %}

When I run the playbook, I get the following error:

 [root@tower ~]#ansible-playbook uid_inventory.yml -K --check
BECOME password:

PLAY [ldap] 
********************************************************************************************

TASK [Obtain Kerberos Ticket on Tower] 
******************************************

TASK [Obtain Kerberos Ticket on LDAP] 
*****************************************************

TASK [Get password entries from getent] 
***********************************************************************
fatal: [ldap]: FAILED! => {"ansible_facts": 
{"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, 
"msg": "Missing arguments, or database unknown."}

PLAY RECAP 
****************************************************************************************************
ldap   : ok=0    changed=0    unreachable=0    failed=1    skipped=2    
rescued=0    ignored=0

Any thoughts/ideas?

Thanks,
Harry

On Wednesday, May 6, 2020 at 3:41:55 PM UTC-4, harry devine wrote:
>
> 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.
>
> Thanks,
> Harry
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/eb72e245-6e5d-48d6-a42c-a50405b0b512%40googlegroups.com.

Reply via email to