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