Infrastructure/ansible/roles/container-user/tasks/main.yml

36 lines
980 B
YAML

---
- name: Check if required parameters are set
ansible.builtin.assert:
that:
- podman_user_name is defined
- name: Set up as container host
ansible.builtin.include_role:
name: container-host
- name: Create user
ansible.builtin.user:
name: "{{ podman_user_name }}"
home: "{{ podman_user_home | default(omit) }}"
uid: "{{ podman_user_uid | default(omit) }}"
state: present
- name: Create unit files dir
ansible.builtin.file:
path: ~/.config/containers/systemd
state: directory
become: true
become_user: "{{ podman_user_name }}"
# Note: We check whether lingering is already enabled so we show as OK/skipped instead of changed
- name: Check if user is lingering
ansible.builtin.stat:
path: "/var/lib/systemd/linger/{{ podman_user_name }}"
register: user_lingering
- name: Enable session lingering
ansible.builtin.command: "loginctl enable-linger {{ podman_user_name }}"
when:
- not user_lingering.stat.exists