i want to query all the users on the hosts of my inventory and create afile 
for each hosts with all the privileges for each user 

I know that htere tools like freeipa but we do not have those in place 

so i am using the getent wrapper to get all the users on the hosts included 
the netgroups.. run sudo -lU on each of these hosts and save the output to 
file by using stdout or stdout_lines. 

the problems is only one username is saved to the file and not all of them 

this is the playbook: 

---
- name: get users from  hosts
  hosts: all
  gather_facts: no

  tasks:

  - name: get users
    getent:
      database: passwd


  - name: get sudo rights
    shell:
      cmd: sudo -lU "{{ item }}"
    loop: "{{ getent_passwd.keys()|flatten(levels=1) }}"
    register: sudo_rights


  - name: debug sudo_rights
    debug:
      msg: "{{item.stdout}}"
    loop: "{{ sudo_rights.results }}"

  - name: save to file
    copy:
      content: "{{item.stdout}}"
      dest: privs_{{inventory_hostnam}}
    loop: "{{ sudo_rights.results }}"
    delegate_to: localhost
    run_once: true


I suspect taht only the last user queried is on the file.. based on the 
debug output but how have them all. 
can copy concatenane should i use a jinja template and use the template 
module instead? 

thank you 


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ce4721cd-24d3-430e-87c3-a50561b8de88%40googlegroups.com.

Reply via email to