On Fri, Mar 27, 2020 at 09:10:32AM -0700, 'Mario Garcia' via Ansible Project 
wrote:
> ---
> - 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? 

This should work:

  - name: save to file
    copy:
      content: "{{ sudo_rights.results | map(attribute='stdout') | join('\n') 
}}"
      dest: privs_{{inventory_hostnam}}
    delegate_to: localhost

You can't use run once, since you need the task to run one time for each host.


-- 
Kai Stian Olstad

-- 
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/20200327180014.62g3fwlbhn7t5flu%40olstad.com.

Reply via email to