2024-02-16 18:01:26 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Check if required parameters are set
|
|
|
|
ansible.builtin.assert:
|
|
|
|
that:
|
2024-02-17 11:00:06 +02:00
|
|
|
- user is defined
|
2024-02-16 21:04:01 +02:00
|
|
|
|
|
|
|
- name: Set up as container host
|
|
|
|
ansible.builtin.include_role:
|
|
|
|
name: container-host
|
2024-02-16 18:01:26 +02:00
|
|
|
|
|
|
|
- name: Create user
|
|
|
|
ansible.builtin.user:
|
2024-02-17 11:00:06 +02:00
|
|
|
name: "{{ user }}"
|
|
|
|
home: "{{ home | default(omit) }}"
|
|
|
|
uid: "{{ uid | default(omit) }}"
|
2024-02-16 18:01:26 +02:00
|
|
|
state: present
|
|
|
|
|
2024-02-18 09:52:10 +02:00
|
|
|
- name: Add public keys for user '{{ user }}'
|
2024-02-16 22:34:58 +02:00
|
|
|
ansible.posix.authorized_key:
|
2024-02-17 11:00:06 +02:00
|
|
|
user: "{{ user }}"
|
2024-02-16 22:34:58 +02:00
|
|
|
key: "{{ lookup('file', '../../access/keys/' + item + '.pub') }}"
|
2024-02-19 10:56:04 +02:00
|
|
|
state: present # Note: we don't remove other/existing keys
|
2024-02-17 11:00:06 +02:00
|
|
|
with_items: "{{ global_ssh_keys + (ssh_keys[user] | default([])) + (ssh_keys['*'] | default([])) }}"
|
2024-02-16 22:34:58 +02:00
|
|
|
|
|
|
|
|
2024-02-16 21:04:01 +02:00
|
|
|
- name: Create unit files dir
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: ~/.config/containers/systemd
|
|
|
|
state: directory
|
2024-02-19 10:56:04 +02:00
|
|
|
mode: "755"
|
2024-02-16 21:04:01 +02:00
|
|
|
become: true
|
2024-02-17 11:00:06 +02:00
|
|
|
become_user: "{{ user }}"
|
2024-02-16 21:04:01 +02:00
|
|
|
|
2024-02-19 10:56:04 +02:00
|
|
|
# Note: We check whether lingering is already enabled
|
|
|
|
# so we don't execute the command if not needed
|
2024-02-16 18:01:26 +02:00
|
|
|
- name: Check if user is lingering
|
2024-02-16 21:04:01 +02:00
|
|
|
ansible.builtin.stat:
|
2024-02-17 11:00:06 +02:00
|
|
|
path: "/var/lib/systemd/linger/{{ user }}"
|
2024-02-16 18:01:26 +02:00
|
|
|
register: user_lingering
|
|
|
|
|
|
|
|
- name: Enable session lingering
|
2024-02-17 11:00:06 +02:00
|
|
|
ansible.builtin.command: "loginctl enable-linger {{ user }}"
|
2024-02-16 18:01:26 +02:00
|
|
|
when:
|
2024-02-16 21:04:01 +02:00
|
|
|
- not user_lingering.stat.exists
|
2024-02-19 10:56:04 +02:00
|
|
|
changed_when: not user_lingering.stat.exists
|