Add install of basic Podman configuration

This commit is contained in:
Ivo C.S. Wingelaar 2024-10-07 03:10:05 +02:00
parent 9d01453d9f
commit 37ac2e0403
Signed by: ivo
GPG key ID: ABBED434F58D0AA3
3 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
sce_cfg_group: sce_cfg
sce_cfg_user: cfg
sce_service_accounts:
- podman

View file

@ -0,0 +1,43 @@
---
- name: Install Podman and dependencies for rootless operation
ansible.builtin.apt:
pkg:
- podman
# Required for rootless operation
- uidmap
# Use the newer network backend instead of the default CNI backend
- netavark
# Required for rootless networking
- slirp4netns
# Next two are required for config management
- systemd-container
- polkitd
- name: Configure polkit for `machinectl` privilege escalation & config management
ansible.builtin.template:
src: machinectl.rules.j2
dest: /etc/polkit-1/rules.d/50-machinectl.rules
mode: "640"
owner: root
group: polkitd
- name: Create group for managing rootless Podman environments
ansible.builtin.group:
name: "{{ sce_cfg_group }}"
state: present
- name: Add config management (Ansible) user to the rootless Podman managing group
ansible.builtin.user:
name: "{{ sce_cfg_user }}"
groups: ["{{ sce_cfg_group }}"]
append: true
- name: Create service account(s) for running rootless Podman containers under
ansible.builtin.user:
name: "{{ item }}"
password_lock: true
comment: "Rootless Podman service account"
# By default, subordinate id's are only allocated automatically for non-system accounts
system: false
state: present
loop: "{{ sce_service_accounts }}"

View file

@ -0,0 +1,6 @@
/* {{ ansible_managed }} */
polkit.addRule(function(action, subject) {
if(action.id == "org.freedesktop.machine1.host-shell" && subject.isInGroup("{{ sce_cfg_group }}")) {
return polkit.Result.YES;
}
});