containers.podman.podman_generate_systemd – Generate systemd unit from a pod or a container¶
Note
This plugin is part of the containers.podman collection (version 1.10.1).
To install it use: ansible-galaxy collection install containers.podman
.
To use it in a playbook, specify: containers.podman.podman_generate_systemd
.
Synopsis¶
Generate systemd .service unit file(s) from a pod or a container
Support Ansible check mode
Requirements¶
The below requirements are needed on the host that executes this module.
Podman installed on target host
Parameters¶
Notes¶
Note
You can store your systemd unit files in
/etc/systemd/user/
for system wide usageOr you can store them in
~/.config/systemd/user/
for usage at a specific userIf you indicate a pod, the systemd units for it and all its containers will be generated
Create all your pods, containers and their dependencies before generating the systemd files
If a container or pod is already started before you do a
systemctl daemon reload
, systemd will not see the container or pod as startedStop your container or pod before you do a
systemctl daemon reload
, then you can start them withsystemctl start my_container.service
Examples¶
# Exemple of creating a container and integrate it into systemd
- name: A postgres container must exist, stopped
containers.podman.podman_container:
name: postgres_local
image: docker.io/library/postgres:latest
state: stopped
- name: Systemd unit files for postgres container must exist
containers.podman.podman_generate_systemd:
name: postgres_local
dest: ~/.config/systemd/user/
- name: Postgres container must be started and enabled on systemd
ansible.builtin.systemd:
name: container-postgres_local
daemon_reload: yes
state: started
enabled: yes
# Generate the unit files, but store them on an Ansible variable
# instead of writting them on target host
- name: Systemd unit files for postgres container must be generated
containers.podman.podman_generate_systemd:
name: postgres_local
register: postgres_local_systemd_unit
# Generate the unit files with environment variables sets
- name: Systemd unit files for postgres container must be generated
containers.podman.podman_generate_systemd:
name: postgres_local
env:
POSTGRES_USER: my_app
POSTGRES_PASSWORD: example
register: postgres_local_systemd_unit
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Sébastien Gendre (@CyberFox001)