Ansible role to deploy docker containers as systemd services on debian-based systems. https://ednz.fr
Go to file
Gitea-Actions 4d4ff0e9e5
All checks were successful
build-deploy / Bump version and create changelog with commitizen (push) Has been skipped
bump: version 0.1.0 → 0.2.0
2024-11-09 18:14:48 +00:00
.gitea/workflows ci: remove old test action in favor of new template one 2024-11-09 10:52:39 +01:00
defaults feat: enable customization of unit options in systemd file 2024-11-09 17:03:46 +01:00
files Initial commit 2023-12-03 14:39:24 +00:00
filter_plugins feat(template): do not print new lines if value of flag is None 2023-12-11 23:45:31 +01:00
handlers feat: make everything mostly work 2023-12-04 23:10:02 +01:00
meta fix: handlers running in unpredictable ways 2024-11-09 11:04:13 +01:00
molecule feat: enable customization of unit options in systemd file 2024-11-09 17:03:46 +01:00
tasks feat: only allow starting and managing running services. 2024-11-09 13:24:14 +01:00
templates feat: enable customization of unit options in systemd file 2024-11-09 17:03:46 +01:00
vars feat: enable customization of unit options in systemd file 2024-11-09 17:03:46 +01:00
.ansible-lint Initial commit 2023-12-03 14:39:24 +00:00
.cz.toml chore: add precommit hooks and commitizen config 2024-11-09 10:49:36 +01:00
.gitignore ci: remove old test action in favor of new template one 2024-11-09 10:52:39 +01:00
.pre-commit-config.yaml chore: add precommit hooks and commitizen config 2024-11-09 10:49:36 +01:00
.yamllint Initial commit 2023-12-03 14:39:24 +00:00
CHANGELOG.md bump: version 0.1.0 → 0.2.0 2024-11-09 18:14:48 +00:00
LICENSE chore: pre-commit fixes 2024-11-09 11:04:34 +01:00
README.md feat: enable customization of unit options in systemd file 2024-11-09 17:03:46 +01:00

Docker systemd service

This role lets you configure a docker container and run it as a systemd service on debian-based distributions. This role is heavily sourced from mhutter.docker-systemd-service, but aims at providing some of the missing features of said role.

Requirements

This roles assumes you have docker installed on the target host. You can use ednz_cloud.install_docker to do so.

Role Variables

Service configuration

docker_systemd_service_container_name: "My-Service"

The name that will be assigned to the container.

docker_systemd_service_image: # by default, not defined

The image (and optionally tag) to use for the service.

docker_systemd_service_start: true

Indicates whether the service should start after installation. Defaults to true.

docker_systemd_service_systemd_unit_options: {}

Extra options to add to the [Unit] section of the systemd unit file. Map of strings.

docker_systemd_service_systemd_service_options: {}

Extra options to add to the [Service] section of the systemd unit file. Map of strings.

docker_systemd_service_name: "{{ docker_systemd_service_container_name }}_container"

The name of the systemd service to register.

Container configuration

docker_systemd_service_container_env: {}

A list of key/value pairs, that will be written to the environment file for the container.

docker_systemd_service_container_pull_image: true

Whether or not the role should pull the image during its run, prior to starting the service.

docker_systemd_service_container_pull_force_source: true

If docker_systemd_service_container_pull_image: true, whether the pull you be executed at every run. See docker_image.force_source

docker_systemd_service_flags: []

This variable lets you pass whatever flags you need to the docker run command. It is a list, to which you can add multiple types of flags:

  •  - key: value
     # will pass the flag --key "value" to the container.
     Example:
       - network: host
    
  •  - simple_key
     # will pass the flag --simple_key to the container.
     Example:
       - privileged
    
  •  - key:
         - value1
         - value2
     # will pass the flags --key "value1" --key "value2" to the container.
     Example:
       - volume:
           - /path/on/host:/path/on/container
           - /var/run/docker.sock:/var/run/docker.sock:ro
    
    

Dependencies

None.

Example Playbook

# calling the role inside a playbook with either the default or group_vars/host_vars
- hosts: servers
  roles:
    - ednz_cloud.docker_systemd_service

License

MIT / BSD

Author Information

This role was created by Bertrand Lanson in 2023.