feat(podman_host): do not create local users and assume a user exists

For SR2's usage, these users will exist because they have been created
in FreeIPA along with their subids.
This commit is contained in:
Iain Learmonth 2025-11-08 20:57:43 +00:00
parent b471a034a4
commit 7792cac0c7
2 changed files with 31 additions and 52 deletions

View file

@ -1,41 +1,26 @@
---
- name: Podman Host | AUDIT | Gather rootless user facts
ansible.builtin.user:
name: "{{ _podman_host_rootless_user }}"
ansible.builtin.getent:
database: passwd
key: "{{ _podman_host_rootless_user }}"
register: _podman_host_rootless_user_facts
- name: Podman Host | AUDIT | Resolve name of user's primary group
ansible.builtin.getent:
database: group
key: "{{ _podman_host_rootless_user_facts.group }}"
register: _podman_host_rootless_user_group
- debug:
msg: "{{ _podman_host_rootless_user_facts }}"
- name: Podman Host | AUDIT | Check if user is in subuid file
ansible.builtin.lineinfile:
path: /etc/subuid
regexp: '^{{ _podman_host_rootless_user }}:.*$'
state: absent
register: _podman_host_uid_line_found
check_mode: true
failed_when: false
changed_when: false
- name: Podman Host | AUDIT | Check if group is in subgid file
ansible.builtin.lineinfile:
path: /etc/subgid
regexp: '^{{ _podman_host_rootless_user_group.ansible_facts.getent_group | first }}:.*$'
state: absent
register: _podman_host_gid_line_found
check_mode: true
failed_when: false
changed_when: false
- name: Podman Host | AUDIT | Assert that user is in subuid file exactly once
- name: Podman Host | AUDIT | Ensure the rootless user exists
ansible.builtin.assert:
that:
- _podman_host_uid_line_found.found == 1
- _podman_host_rootless_user in _podman_host_rootless_user_facts.ansible_facts.getent_passwd.keys()
fail_msg: "User '{{ _podman_host_rootless_user }}' does not exist on this host."
- name: Podman Host | AUDIT | Ensure the rootless user has subuids defined
ansible.builtin.command:
cmd: "getsubids {{ _podman_host_rootless_user }}"
changed_when: false
- name: Podman Host | AUDIT | Ensure the rootless user has subgids defined
ansible.builtin.command:
cmd: "getsubids -g {{ _podman_host_rootless_user }}"
changed_when: false
- name: Podman Host | AUDIT | Assert that group is in subgid file exactly once
ansible.builtin.assert:
that:
- _podman_host_gid_line_found.found == 1