Ansible Role linuxfabrik.lfops.podman_containers¶
This role installs Podman and deploys Quadlets to configure containers, networks and volumes. The role supports running rootless containers.
Available since LFOps 3.0.0.
Requirements¶
Manual steps:
- Optional: when running rootless containers, create a user with lingering enabled by running the login playbook (role: linuxfabrik.lfops.login):
login__users__host_var: - name: 'example' home: '/opt/example' state: 'present' linger: true -
Optional: when running rootless containers, note that the kernel_modules role, which
setup_basicruns, blocks thetunkernel module by default. Rootless container networking (pasta, slirp4netns) needs it, so allow it in the inventory:kernel_modules__modules__host_var: - name: 'tun' enabled: true -
Optional: when running rootful containers on a network of their own with a FirewallFabrik nftables script, disable "Flush entire ruleset" in the firewall settings. Otherwise every start of the firewall deletes the rules netavark set up, and the published ports of these containers stop answering until
podman network reload --all. The policy also has to accept the forwarded traffic to and from the container networks, see Coexistence with Docker, CrowdSec, fail2ban and Other Tools in the FirewallFabrik user guide. Rootless containers are not affected, their rules live in the network namespace of their user.
Tags¶
podman_containers
- Installs Podman, deploys Quadlets and manages their state.
- Triggers: none.
podman_containers:auto_update
- Manages podman-auto-update.timer for system and users.
- Triggers: none.
podman_containers:containers
- Deploys and removes container Quadlets.
- Triggers: none.
podman_containers:networks
- Deploys and removes network Quadlets.
- Triggers: none.
podman_containers:state
- Manages the state of the containers, networks and volumes. Restarts a running container whose unit changed in the same run.
- Triggers: none.
podman_containers:volumes
- Deploys and removes volume Quadlets.
- Triggers: none.
Optional Role Variables¶
podman_containers__auto_update__host_var / podman_containers__auto_update__group_var
- List of dictionaries controlling
podman-auto-update.timer. - Type: List of dictionaries.
- Default:
[] -
Subkeys:
-
on_calendar:- Optional. Custom schedule for the timer in systemd calendar format (e.g.,
daily,weekly,*-*-* 04:00:00). When specified, creates an override file to customize the schedule. Uses systemd defaultdailywhen unset. - Type: String.
- Default: unset
- Optional. Custom schedule for the timer in systemd calendar format (e.g.,
-
state:- Optional. State of the timer. Possible options:
present(enable and start),absent(disable and stop). - Type: String.
- Default:
'present'
- Optional. State of the timer. Possible options:
-
user:- Mandatory. Username for which to manage the timer. Use
rootfor the system-wide timer. - Type: String.
- Mandatory. Username for which to manage the timer. Use
-
podman_containers__containers__host_var / podman_containers__containers__group_var
- List of dictionaries describing the Podman containers.
- Type: List of dictionaries.
- Default:
[] -
Subkeys:
-
enabled:- Optional. Set
trueto start the container at boot. - Type: Bool.
- Default:
true
- Optional. Set
-
name:- Mandatory. Name of the quadlet file. Will be suffixed with
-container.service. - Type: String.
- Mandatory. Name of the quadlet file. Will be suffixed with
-
raw_container:- Optional. Raw block in the
[Container]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_install:- Optional. Raw block in the
[Install]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_service:- Optional. Raw block in the
[Service]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_unit:- Optional. Raw block in the
[Unit]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
state:- Optional. State of the container. Possible options:
present,absent,started(impliespresent),stopped(impliespresent). - Type: String.
- Default:
'started'
- Optional. State of the container. Possible options:
-
user:- Optional. Set this to run the container as rootless.
- Type: String.
- Default: unset (rootful)
-
wanted_by:- Optional. Unit for the
WantedBydirective. Only effective ifenabled: trueis set. - Type: String.
- Default:
'default.target'
- Optional. Unit for the
-
podman_containers__networks__host_var / podman_containers__networks__group_var
- List of dictionaries describing the Podman networks.
- Type: List of dictionaries.
- Default:
[] -
Subkeys:
-
enabled:- Optional. Set
trueto start the network at boot. - Type: Bool.
- Default:
true
- Optional. Set
-
name:- Mandatory. Name of the quadlet file. Will be suffixed with
-network.service. - Type: String.
- Mandatory. Name of the quadlet file. Will be suffixed with
-
raw_network:- Optional. Raw block in the
[Network]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_install:- Optional. Raw block in the
[Install]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_service:- Optional. Raw block in the
[Service]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_unit:- Optional. Raw block in the
[Unit]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
state:- Optional. State of the network. Possible options:
present,absent,started(impliespresent),stopped(impliespresent). - Type: String.
- Default:
'started'
- Optional. State of the network. Possible options:
-
user:- Optional. Set this to run the corresponding container as rootless.
- Type: String.
- Default: unset (rootful)
-
wanted_by:- Optional. Unit for the
WantedBydirective. Only effective ifenabled: trueis set. - Type: String.
- Default:
'default.target'
- Optional. Unit for the
-
podman_containers__volumes__host_var / podman_containers__volumes__group_var
- List of dictionaries describing the Podman volumes.
- Type: List of dictionaries.
- Default:
[] -
Subkeys:
-
enabled:- Optional. Set
trueto start the volume at boot. - Type: Bool.
- Default:
true
- Optional. Set
-
name:- Mandatory. Name of the quadlet file. Will be suffixed with
-volume.service. - Type: String.
- Mandatory. Name of the quadlet file. Will be suffixed with
-
raw_volume:- Optional. Raw block in the
[Volume]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_install:- Optional. Raw block in the
[Install]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_service:- Optional. Raw block in the
[Service]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
raw_unit:- Optional. Raw block in the
[Unit]section. - Type: String.
- Default: unset
- Optional. Raw block in the
-
state:- Optional. State of the volume. Possible options:
present,absent,started(impliespresent),stopped(impliespresent). - Type: String.
- Default:
'started'
- Optional. State of the volume. Possible options:
-
user:- Optional. Set this to run the corresponding container as rootless.
- Type: String.
- Default: unset (rootful)
-
wanted_by:- Optional. Unit for the
WantedBydirective. Only effective ifenabled: trueis set. - Type: String.
- Default:
'default.target'
- Optional. Unit for the
-
Example:
# optional
podman_containers__auto_update__host_var:
- user: 'root'
state: 'present'
on_calendar: '*-*-* 04:00:00' # run at 4 AM every day
- user: 'rocketuser'
state: 'present'
on_calendar: 'weekly'
podman_containers__containers__host_var:
- name: 'rocketchat'
raw_container: |
AutoUpdate=registry
ContainerName=rocketchat
EnvironmentFile=/opt/rocketchat/rocketchat.env
HealthCmd=curl --fail --show-error --silent --max-time 2 http://localhost:3000
HealthInterval=30s
HealthOnFailure=kill
HealthRetries=5
HealthStartPeriod=5s
HealthTimeout=10s
Image=registry.rocket.chat/rocketchat/rocket.chat:latest
LogDriver=journald
Network=rocketchat.network
PublishPort=3000:3000/tcp
User=rocketchat
UserNS=keep-id:uid=1000,gid=1000
raw_service: |
Restart=always
user: 'rocketuser'
podman_containers__networks__host_var:
- name: 'rocketchat'
user: 'rocketuser'
podman_containers__volumes__host_var:
- name: 'rocketchat'
user: 'rocketuser'
Troubleshooting¶
Failed to enable unit: Unit ... is transient or generated.
- Since the units are generated,
systemctl enable/disablehas no effect. Autostarting is handled by thepodman-system-generatorbased on theWantedBysetting in the quadlet. Have a look atman podman-systemd.unitfor details.