I have gathered the list of all users using getent_module:
- name: Get user info
getent:
database: passed
This returns this variable as getent_passwd, a dictionary like this:
{
"uuidd": [
"x",
"107",
"112",
"",
"/run/uuidd",
"/usr/sbin/nologin"
],
"www-data": [
"x",
"33",
"33",
"www-data",
"/var/www",
"/usr/sbin/nologin"
]
}
I'm trying to return an array of users, including some specific users, finding the key of item.value in which "/home" is a part of one of the value array items and "nologin" is not. This is the code I have written so far, but it is not correct.
- name: style the user list
set_fact:
my_users: "{{ item.key | default([]) }}"
when:
- "'nologin' not in (item.value)"
- "'/home' search in (item.value)"
loop: "{{ lookup('dict', getent_passwd) }}"
How should I change my conditions to get the expected result?