Welcome, Guest! Registration

loc2log

Thursday, 2024-11-21
Main » 2020 » July » 04

It is easy to detect if a user is registered on a Linux system with Ansible getent module.

Example:

- name: Check if user exists
  getent:
    database: passwd
    key: "{{ user_name }}"
    fail_key: False
- debug: var=getent_password

Here we simply use user_name variable with whatever user we need to find. And the result goes to an auto-registered variable "getent_password". If the user we are looking for is not there, we get dictionary with null value. E.g. we were looking for user_name: super, then the debug output will look like this:

getent_passwd:
  super: null

Views: 8298 | Added by: ep | Date: 2020-07-03 | Comments (0)