On Wed, 24 Aug 2022 05:05:14 -0700 (PDT)
Kenady Inampudi <ken...@cis-in.com> wrote:

>   tasks:
>     - getent:
>         database: passwd
>         key: ^ora.*$'
>       register: userid
>       ignore_errors: true
>     - command: "id {{ item }}"
>       register: id
>       loop: "{{ userid.stdout_lines }}"
>     - debug:
>         msg: "{{ id.results|map(attribute='stdout')|list }}"

Try

- hosts: node1.example.com
  gather_facts: false
  vars:
    users: "{{ getent_passwd.keys()|list }}"
  tasks:
    - getent:
        database: passwd
    - command: "id {{ item }}"
      register: id
      loop: "{{ users|select('match', '^user.*$') }}"
    - debug:
        msg: "{{ id.results|map(attribute='stdout')|list }}"

Notes:

* The module *getent* stores the data automagically. In the case of
  *passwd* the dictionary will be *getent_passwd*

* Put the declaration of *users* into vars

* Fit the regex to your needs and iterate the selected users

* The debug of the results is the same as before

* Take a look at *getent_passwd*

* The same way you can get the content of /etc/group in the
  dictionary *getent_group*

* You can create any structure you like when you have both
  dictionaries *getent_passwd* and *getent_group*


-- 
Vladimir Botka

-- 
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/20220824143235.292f328d%40gmail.com.

Attachment: pgp8mlG4EgXOn.pgp
Description: OpenPGP digital signature

Reply via email to