This role creates user accounts and adds SSH keys.
This role requires the ansible.posix
collection.
Install it via:
ansible-galaxy collection install ansible.posix
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:
orhttps:
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
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
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.