Verified Commit 72395058 authored by Maciej Delmanowski's avatar Maciej Delmanowski

Merge branch 'drybjed-alternative-local-getent'

parents 6282db84 9dfc582d
Pipeline #62751788 passed with stages
in 15 minutes and 28 seconds
#!/usr/bin/env python
# Get the specified user information from the system password database.
# This solution should work on all platforms; Ansible 'getent' module does not
# work correctly on Apple macOS.
# Ref:
# Usage: <username>
import sys
import os
import pwd
import operator
from json import dumps
def getent(user):
all = pwd.getpwall()
user = sorted(
(u for u in all if u.pw_name == user),
return ({user.pw_name: ["x", user.pw_uid, user.pw_gid, user.pw_gecos,
user.pw_dir, user.pw_shell]})
if __name__ == "__main__":
user = sys.argv[1]
print(dumps(getent(user), sort_keys=True, indent=4))
except IndexError:
except Exception:
print("Usage: %s <user>" % os.path.basename(sys.argv[0]))
- name: Gather local Ansible user details
database: 'passwd'
key: '{{ system_users__self_name }}'
script: 'script/ {{ system_users__self_name }}'
register: system_users__register_passwd
delegate_to: 'localhost'
become: False
changed_when: False
check_mode: False
run_once: True
- name: Remember local Ansible user details
system_users__fact_self_comment: '{{ getent_passwd[system_users__self_name][3] }}'
system_users__fact_self_shell: '{{ getent_passwd[system_users__self_name][5] }}'
system_users__fact_self_comment: '{{ (system_users__register_passwd.stdout|from_json)[system_users__self_name][3] }}'
system_users__fact_self_shell: '{{ (system_users__register_passwd.stdout|from_json)[system_users__self_name][5] }}'
- name: Ensure that reqired packages are installed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment