monolithprojects.user_management

User Management

Last version Galaxy Quality Galaxy Downloads GitHub Actions

This Ansible role helps you manage Linux users, allowing you to create, edit, or delete them. It also helps with organizing SSH keys.

How It Works

This role uses local facts on each host to keep track of user names listed in user_management. Only the users in this list are managed by the role. If you remove a user from the list, both the user and their home directory will be deleted from the host. Users not included in the list (those not created by this role) will not be affected.

This Role Can

  • Create users
  • Delete users
  • Edit users
  • Manage SSH keys

Requirements

  • Supported Linux distributions:

    • CentOS/RHEL 7, 8
    • Debian 9, 10
    • Fedora 29, 30, 31, 32
    • Ubuntu 16, 18, 20

    Note: These distributions are regularly tested. The role should work on other Linux distributions too.

Role Variables

Here’s a copy from defaults/main.yml

local_facts_file: linux_users.fact
local_facts_path: /etc/ansible/facts.d
user_management:
#   - name: userx                       <<< User name (Required).
#     comment: User X                   <<< (Optional) Description of the user.
#     groups:                           <<< (Optional) List of groups the user will join.
#       - games
#       - video
#     ssh_keys:                         <<< (Optional) List of authorized public keys.
#       - 'ssh-ed25519 xxxx something'
#     shell: /bin/bash                  <<< (Optional) User’s shell (default is "/bin/bash").
#     expires: -1                       <<< (Optional) User expiration date in epoch format (default is "-1").
#     create_home: yes                  <<< (Optional) Create a home directory (default is "yes").
#     system: no                        <<< (Optional) Create a system account (default is "no").

Playbook Example:

This example shows how to use Ansible to create (or edit if it's not the first run) 3 users. user1 has a description, uses zsh as the default shell, expires at 1640991600 Unix epoch time, belongs to sudo and docker groups, and has two SSH keys added. user2 is created with default settings. appuser is created as a system user without a home directory.

---
- name: User Management
  hosts: all
  user: ubuntu
  gather_facts: yes
  become: yes
  vars:
  
    user_management:
      - name: user1
        comment: My Test User
        shell: /bin/zsh
        expires: 1640991600
        groups:
          - sudo
          - docker
        ssh_keys:
          - 'ssh-ed25519 xxxxxx my_user_key'
          - 'ssh-rsa xxxxxx my_user_key'

      - name: user2

      - name: appuser
        system: yes
        create_home: no

  roles:
      - ansible-user_management

License

MIT

Author Information

Created in 2020 by Michal Muransky

Informazioni sul progetto

Linux users and ssh keys management

Installa
ansible-galaxy install monolithprojects.user_management
Licenza
Unknown
Download
61k
Proprietario
Full-time Cloud Engineer, part-time adventurer