44 lines
1.3 KiB
YAML
Raw Normal View History

2024-02-16 18:01:26 +02:00
---
- name: Check if required parameters are set
ansible.builtin.assert:
that:
2024-02-16 21:04:01 +02:00
- podman_user_name is defined
- 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-16 21:04:01 +02:00
name: "{{ podman_user_name }}"
home: "{{ podman_user_home | default(omit) }}"
uid: "{{ podman_user_uid | default(omit) }}"
2024-02-16 18:01:26 +02:00
state: present
- name: Add public keys for user '{{ podman_user_name }}'
ansible.posix.authorized_key:
user: "{{ podman_user_name }}"
key: "{{ lookup('file', '../../access/keys/' + item + '.pub') }}"
state: present # Note: we don't remove other/existing keys
with_items: "{{ global_ssh_keys + (ssh_keys[podman_user_name] | default([])) + (ssh_keys['*'] | default([])) }}"
2024-02-16 21:04:01 +02:00
- name: Create unit files dir
ansible.builtin.file:
path: ~/.config/containers/systemd
state: directory
become: true
become_user: "{{ podman_user_name }}"
2024-02-16 18:01:26 +02:00
# Note: We check whether lingering is already enabled so we show as OK/skipped instead of changed
- name: Check if user is lingering
2024-02-16 21:04:01 +02:00
ansible.builtin.stat:
path: "/var/lib/systemd/linger/{{ podman_user_name }}"
2024-02-16 18:01:26 +02:00
register: user_lingering
- name: Enable session lingering
2024-02-16 21:04:01 +02:00
ansible.builtin.command: "loginctl enable-linger {{ podman_user_name }}"
2024-02-16 18:01:26 +02:00
when:
2024-02-16 21:04:01 +02:00
- not user_lingering.stat.exists