From abbc5c8ab83037eea9a6d9acb926bfb4fe9b6de1 Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Mon, 10 Jan 2022 12:47:51 -0500 Subject: [PATCH] Suppress 'Service' directive if ListenStream is specified This is mutually exclusive configuration Change-Id: Icf43a8421f4d52570ea89f5db0722c0d99bafd85 --- defaults/main.yml | 3 ++- templates/systemd-socket.j2 | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 8dda35b..6250012 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -129,7 +129,8 @@ systemd_environment: {} # `before_targets` -- (optional) Start the socket before this list of dependency units. # `bind_targets` -- (optional) Bind the socket to this dependency unit. # `enabled` -- (optional) Set the enabled state of the socket. -# `options` -- (optional) Additional options, like `ListenStream` or other +# `options` -- (optional) Additional options, like `ListenStream` or other. Specifying ListenStream in +# the options will suppress the default 'Service' field in [Socket]. # `state` -- (optional) Set the running state of the socket. # Under the service dictionary the "timer" key can be added which will enable a given service diff --git a/templates/systemd-socket.j2 b/templates/systemd-socket.j2 index a3206e2..3366fbe 100644 --- a/templates/systemd-socket.j2 +++ b/templates/systemd-socket.j2 @@ -13,7 +13,10 @@ BindsTo={{ target }} {% endfor %} [Socket] +{% if 'ListenStream' not in item.1.options %} Service={{ item.0.service_name | replace(' ', '_') }}.service +{% endif %} + {% for key, var in item.1.options.items() | default({}) %} {{ key }}={{ var }} {% endfor %}