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
This commit is contained in:
Cédric Jeanneret 2022-09-13 15:52:42 +02:00
parent e36aaed0e8
commit fea789f8e5

View File

@ -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