From fea789f8e520c47ecbc8fa78ef99bdf76ddf1aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Tue, 13 Sep 2022 15:52:42 +0200 Subject: [PATCH] Avoid a pipe and grep call systemctl list-unit-files is nice enough to actually directly filter on the value of the first positional parameter. This allows us to use a simple "command", avoid a pipe and a potential "broken pipe" due to the "-q" option passed to grep (we were bitten enough in the healthchecks back then). The failed_when condition is also a bit stronger: we accept only 2 exit code, any other will raise a failure. 0: success, unit found, whatever its state is 1: failure, unit not found Change-Id: I142dc63af3800d54996e11104dc776ca1a113fc4 --- deployment/metrics/collectd-container-puppet.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/metrics/collectd-container-puppet.yaml b/deployment/metrics/collectd-container-puppet.yaml index 12b860c151..6d957f5622 100644 --- a/deployment/metrics/collectd-container-puppet.yaml +++ b/deployment/metrics/collectd-container-puppet.yaml @@ -618,9 +618,9 @@ outputs: - step|int == 1 block: - name: Check if rsyslog exists - shell: systemctl list-unit-files --type=service | grep -q rsyslog + command: systemctl list-unit-files --type=service rsyslog.service register: rsyslog_config - failed_when: rsyslog_config.rc == 2 + failed_when: rsyslog_config.rc not in [0, 1] - name: Configure if we can when: - rsyslog_config is changed