Trying to check if a user exists locally and if true, check to see if it has sudo rights. I can’t seem to process the second loop. I tried using out.results.item but error:
fatal: [hostname]: FAILED! => {“msg”: “‘list object’ has no attribute ‘item’”}
You forgot the output.
Also, what is your high level goal.
Why do you need to know if a user exists and has sudo permission.
My bigger question is how to run a loop with with_items then process the output in the second play.
The objective is to see if user1, user2, user3 exist locally make sure they have sudo rights.
when my play tries to process out.results.item:
- name: check if existing user is in sudoers
command: grep {{ item }} /etc/sudoers
with_items: “{{ out.results.item }}”
register: message
TASK [check if existing user is in sudoers] ****************************************************************************************************************************************************************
fatal: [hostname]: FAILED! => {“msg”: “‘list object’ has no attribute ‘item’”}
to retry, use: --limit @/opt/rhel-ansible/check_sudo_users.retry
If I leave the playbook like this:
- name: check if existing user is in sudoers
command: grep {{ item }} /etc/sudoers
with_items: “{{ out.results }}”
register: message
it attempts to run a grep on all output from out.results.
My bigger question is how to run a loop with with_items then process the output in the second play.
The objective is to see if user1, user2, user3 exist locally make sure they have sudo rights.
See
https://docs.ansible.com/ansible/latest/modules/user_module.html
This almost works but I cant make it skip when the grep root /etc/password fails. I dont understand how to access out.rc when using a loop. My when statement doesnt work. I am not as interested in this task as I am pulling rc from a loop then using it in the next loop.