Skip to content
Snippets Groups Projects
Commit e90d126d authored by ale's avatar ale
Browse files

Do not attempt to restart systemd services which do not exist

The first time float is run the services associated with credentials
won't have been installed yet, which causes an error.
parent 29e20694
No related branches found
No related tags found
1 merge request!183Reduce the number of expected errors
...@@ -6,6 +6,14 @@ ...@@ -6,6 +6,14 @@
name: x509ca name: x509ca
state: present state: present
# Get the list of currently known systemd service units. Unfortunately
# the systemd version in Debian Buster does not yet support --output
# to set a reasonable format, so we have to use 'awk'.
# This will be used to restart services only if they actually exist.
- name: List systemd service units
shell: "systemctl list-units --no-legend --no-pager --full --type service | awk '{print $1}'"
register: all_systemd_units
# Get the credential names from the list of certs. # Get the credential names from the list of certs.
- set_fact: - set_fact:
credentials_names: "{{ credentials | map(attribute='credentials') | map(attribute='name') | unique | list }}" credentials_names: "{{ credentials | map(attribute='credentials') | map(attribute='name') | unique | list }}"
...@@ -95,7 +103,7 @@ ...@@ -95,7 +103,7 @@
# This should use the systemd module but it doesn't take lists of services. # This should use the systemd module but it doesn't take lists of services.
- name: "Restart associated services" - name: "Restart associated services"
shell: "systemctl restart {{ services[item.0.service].systemd_services | join(' ') }}" shell: "systemctl restart {{ all_systemd_units.stdout_lines | intersect(services[item.0.service].systemd_services) | join(' ') }}"
when: "item.1.changed and item.0.service != 'LOCAL' and services[item.0.service].systemd_services" when: "item.1.changed and item.0.service != 'LOCAL' and services[item.0.service].systemd_services"
loop: "{{ credentials | zip(x509_sign.results) | list }}" loop: "{{ credentials | zip(x509_sign.results) | list }}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment