Ansible Role: users

All user accounts (except the default ubuntu account) are managed through a custom users Ansible role. Users are defined in a dictionary called users, where the dictionary key corresponds to the user name, and the value contains settings for that user.

The following properties can be set for each user:

Property

Description

admin

Setting this to true will add the user to the sudoers on the system.

groups

Groups to add the user to. Groups that do not exist yet are created automatically.

ssh_key

Used to add a single SSH key to the user’s .ssh/authorized_keys file.

ssh_keys

Used to add multiple SSH keys to the user’s .ssh/authorized_keys file.

So, to add a user named foo, define the following:

users:
  foo:
    ssh_key: ssh-rsa abcdef...

Or, a more complex example:

users:
  foo:
    admin: true
    groups: custom,groups,to,assign
    ssh_keys:
      - "{{ lookup('file', 'path/to/first/key.pub') }}"
      - "{{ lookup('file', 'path/to/second/key.pub') }}"
      - ssh-rsa inline-key