Skip to content

Ansible role to manage user accounts on Linux servers

License

Notifications You must be signed in to change notification settings

virtUOS/user_setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Role to Add Unix User Accounts

This role creates user accounts and adds SSH keys.

Requirements

This role requires the ansible.posix collection. Install it via:

ansible-galaxy collection install ansible.posix

Role Variables

Have a look at the defaults to see what variables you can set.

You will need to specify the variable user_setup_admins as a list of usernames and SSH keys. Public keys can be specified as strings, URLs or local files.

  • To specify a key directly, just provide the key as string.
  • To load a key from file, prefix the path with the file: schema.
  • To load a key from a URL, specify a URL with http: or https: schema.
user_setup_admins:
  - name: foo
    key: http://example.com/foo.pub
  - name: bar
    key: file:ssh-keys/bar.pub
  - name: baz
    key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF83wYwFxccj6boydYE5yoh+Tabuon7Uuu4HGlHrbpSt

Example Playbook

Just add the role to your playbook and specify your template:

In your requirements.yml:

- src: https://github.com/virtUOS/user_setup.git
  scm: git
  version: 1.0.0

An example playbook to create two admin unsers and detele all other users:

- hosts: all
  become: true
  roles:
    - role: user_setup
      user_setup_delete_users: true
      user_setup_admins:
        - name: foo
          key: http://example.com/foo.pub
        - name: bar
          key: file:ssh-keys/bar.pub
        - name: baz
          key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF83wYwFxccj6boydYE5yoh+Tabuon7Uuu4HGlHrbpSt

Deleting Users

If user_setup_delete_users is set to true (default), the role will try to delete all users not in user_setup_admins. Users created via this role are part of the group managed. The users being deleted are all users in the group managed which are not defined in user_setup_admins. Users with are not in the group managed will not be touched by this role.

License

BSD-3-Clause

About

Ansible role to manage user accounts on Linux servers

Resources

License

Stars

Watchers

Forks