webofmars.users

ansible-users

This is a role for managing users on a computer system.

Role Configuration

  • users_create_per_user_group (default: true): When you create a user, this option will also create a group with the same name as the user and set it as the user’s main group.
  • users_group (default: users): If the option above is not enabled, this will be the main group for all created users.
  • users_default_shell (default: /bin/bash): This is the default shell for users if no specific shell is set.
  • users_create_homedirs (default: true): Set this to true to create home directories for new users. If you manage home directories separately, set this to false.

Creating Users

To add users, create a variable called users that includes a list of the users you want to add. A good place for this variable is in group_vars/all or in group_vars/groupname for specific machines.

Each user requires the following details:

  • username: The name the user will use to login.
  • name: The full name of the user.
  • home: The home directory for the user (optional, defaults to /home/username).
  • uid: The unique numeric ID for the user. This is needed for consistency across systems.
  • gid: The numeric group ID for the group (optional). If not provided, the uid will be used.
  • password: If you provide a hash, it will be used for the password; otherwise, the account will be locked.
  • update_password: Can be 'always' (updates passwords if they differ, default) or 'on_create' (sets password only for new users).
  • group: Optional main group override.
  • groups: A list of additional groups for the user.
  • profile: Custom shell profile settings.
  • ssh_authorized_keys: A list of SSH keys for the user (no newlines).

Additionally, the following options are available for each user:

  • generate_ssh_key: Whether to create an SSH key for the user (optional, defaults to no).
  • ssh_priv_key: The user's SSH private key in RSA format.
  • shell: The user's shell (defaults to /bin/bash). This can be changed using the users_default_shell.

Example:

users:
  - username: foo
    name: Foo Barrington
    groups: ['wheel','systemd-journal']
    uid: 1001
    home: /local/home/foo
    profile: |
      alias ll='ls -lah'
    ssh_authorized_keys:
      - "ssh-rsa AAAAA.... foo@machine"
      - "ssh-rsa AAAAB.... foo2@machine"
    ssh_priv_key: |
      -----BEGIN RSA PRIVATE KEY-----
      Key Content <...>
      -----END RSA PRIVATE KEY-----
groups_to_create:
  - name: developers
    gid: 10000
users_deleted:
  - username: bar
    name: Bar User
    uid: 1002

Deleting Users

The users_deleted variable lists users that should be removed from the system. They will be deleted in the next Ansible run. The format is the same as for adding users, but only the username is required. It’s a good idea to keep the uid for reference to avoid reusing IDs by mistake.

Informazioni sul progetto

provision users and groups on linux servers

Installa
ansible-galaxy install webofmars.users
Licenza
mit
Download
298
Proprietario
webofmars is a devops & IT company based in Marseille, France