2023-12-03 21:56:21 +00:00
|
|
|
# {{ ansible_managed }}
|
|
|
|
{% macro params(name, vals) %}
|
|
|
|
{% for v in vals %}{{ name }} {{ v }} {% endfor %}
|
|
|
|
{% endmacro %}
|
2023-12-04 22:10:02 +00:00
|
|
|
{% set service_systemd_options_keys = docker_systemd_service_systemd_options | selectattr("key") | map(attribute="key") | list %}
|
2023-12-03 21:56:21 +00:00
|
|
|
[Unit]
|
2023-12-04 22:10:02 +00:00
|
|
|
{% for key, value in docker_systemd_service_systemd_unit_options | dictsort %}
|
2023-12-03 21:56:21 +00:00
|
|
|
{{ key }}={{ value }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
[Service]
|
2023-12-04 22:10:02 +00:00
|
|
|
{% for item in docker_systemd_service_systemd_options %}
|
2023-12-03 21:56:21 +00:00
|
|
|
{{ item['key'] }}={{ item['value'] }}
|
|
|
|
{% endfor %}
|
2023-12-04 22:10:02 +00:00
|
|
|
{% if docker_systemd_service_container_env is defined %}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% if not 'EnvironmentFile' in service_systemd_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
EnvironmentFile={{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% if not 'ExecStartPre' in service_systemd_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
ExecStartPre=-{{ docker_systemd_service_docker_path }} rm -f {{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if not 'ExecStart' in service_systemd_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
{% if docker_systemd_service_container_env is defined %}ExecStart={{ docker_systemd_service_docker_path }} run --name {{ docker_systemd_service_container_name }} --rm --env-file {{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }} {% endif %}\
|
|
|
|
{{ params('--volume', docker_systemd_service_container_volumes)~' \\'| trim }}
|
|
|
|
{% if docker_systemd_service_container_host_network == true %}--network host \{% else %}{{ params('--publish', docker_systemd_service_container_ports)~'\\'| trim }}{% endif +%}
|
|
|
|
{% if docker_systemd_service_container_network %}--network {{ docker_systemd_service_container_network }} {% endif %}\
|
|
|
|
{% if docker_systemd_service_container_user %}--user {{ docker_systemd_service_container_user }} {% endif %}\
|
|
|
|
{% if docker_systemd_service_container_hostname %}--hostname {{ docker_systemd_service_container_hostname }} {% endif %}\
|
|
|
|
{{ params('--link', docker_systemd_service_container_links)~' \\'| trim }}
|
|
|
|
{{ params('--add-host', docker_systemd_service_container_hosts)~' \\'| trim }}
|
|
|
|
{{ params('--label', docker_systemd_service_container_labels)~' \\'| trim }}
|
|
|
|
{{ params('--cap-add', docker_systemd_service_container_cap_add)~' \\'| trim }}
|
|
|
|
{{ params('--cap-drop', docker_systemd_service_container_cap_drop)~' \\'| trim }}
|
|
|
|
{{ params('--device', docker_systemd_service_container_devices)~' \\'| trim }}
|
|
|
|
{% if docker_systemd_service_container_privileged == true %}--privileged {% endif %}\
|
|
|
|
{{ docker_systemd_service_container_args~' \\'| trim}}
|
2023-12-05 18:23:38 +00:00
|
|
|
{{ docker_systemd_service_image -}}{{ ' ' if docker_systemd_service_container_cmd else '' }}{% if docker_systemd_service_container_cmd is string %}{{ docker_systemd_service_container_cmd | trim }}{% else %}{{ docker_systemd_service_container_cmd | join(' ') | trim }}{% endif %}
|
|
|
|
{% endif +%}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% if not 'ExecStop' in service_systemd_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
ExecStop={{ docker_systemd_service_docker_path }} stop {{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if container_start_post is defined %}
|
|
|
|
ExecStartPost=-{{ container_start_post }}
|
|
|
|
{% endif %}
|
|
|
|
{% if not 'SyslogIdentifier' in service_systemd_options_keys %}
|
2023-12-04 22:10:02 +00:00
|
|
|
SyslogIdentifier={{ docker_systemd_service_container_name }}
|
2023-12-03 21:56:21 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if not 'Restart' in service_systemd_options_keys %}
|
|
|
|
Restart=always
|
|
|
|
{% endif %}
|
|
|
|
{% if not 'RestartSec' in service_systemd_options_keys %}
|
|
|
|
RestartSec=10s
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
[Install]
|
2023-12-04 22:10:02 +00:00
|
|
|
WantedBy=docker.service
|