mhutter / ansible-docker-systemd-service

Ansible role for creating Systemd services for docker containers
https://galaxy.ansible.com/mhutter/docker-systemd-service
MIT License
48 stars 30 forks source link

templates/unit.j2: issue with jinja trim whith endif #42

Closed talset closed 2 years ago

talset commented 2 years ago

Recently templates/unit.j2 has been updated with if condition around container_cmd

{{ container_image }} {% if container_cmd is string %}{{ container_cmd | trim }}{% else %}{{ container_cmd | join(' ') | trim }}{% endif %}

It seems jinja trim line ending by "if" condition and we end up with systems config like

ExecStart=/usr/bin/docker run \
  --name vault \
  --rm \
  --env-file /etc/default/vault \
  --volume /opt/cycloid/vault/config:/vault/config --volume /opt/cycloid/vault/file:/vault/file \
  --publish 8200:8200 \
   \
  \
  \
  \
  \
  \
  --cap-add IPC_LOCK \
  vault:1.5.4 vault server -config /vault/config/local.jsonExecStop=/usr/bin/docker stop vault
ExecStartPost=-/opt/cycloid/vault/unseal.sh

As you can see the newline before ExecStop is not respected. Should we force a new line before ExecStop ?

Version ansible 2.9.27 jinja2 2.10-2

mhutter commented 2 years ago

Ah yeah, if I remember correctly Jinja removes some newlines around blocks under certain circumstances