You can make your shell command much more efficient. No need to use cat and 
grep.

awk -F: '$1 ~ /^ora/ { print $1 }' /etc/passwd

This will find and print all usernames that begin "ora".

    - shell: "awk -F: '$1 ~ /^ora/ { print $1 }' /etc/passwd"
      register: userid
      ignore_errors: true

Then you can look at userid.results.stdout_lines (as a list) to see the list of 
usernames.

    - debug: var=userid.results.stdout_lines

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Aug 24, 2022, at 6:37 AM, Vladimir Botka 
<[email protected]<mailto:[email protected]>> wrote:

On Wed, 24 Aug 2022 02:17:38 -0700 (PDT)
Kenady Inampudi <[email protected]<mailto:[email protected]>> wrote:

   - shell: id "{{ item }}"
     register: id
     with_items: "{{ userid.stdout.split('\n') }}"
   - debug:
       var: id.stdout_lines

The variable *id* was registered in a loop. You need the attribute
*results*. (Take a look at *id*.)

Try

   - debug:
       msg: "{{ id.results|map(attribute='stdout')|list }}"


Notes:

* Use *getent* instead of reading /etc/passwd* on your own
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/getent_module.html

* Use *command* instead of *shell*, *loop* instead of *with_items*,
 and *userid.stdout_lines* instead of *userid.stdout.split('\n')*

   - command: "id {{ item }}"
     register: id
     loop: "{{ userid.stdout_lines }}"

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20220824123753.15430d86%40gmail.com.

-- 
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/024F833E-E54C-4D4D-9827-FEDF5D915CF0%40nist.gov.

Reply via email to