From 7173a9f73126eca1cc36bd6997acf10ac75832ff Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 2 Feb 2022 12:04:04 +0000 Subject: [PATCH] ntp: Fix service mask when service doesn't exist The ntp role attempts to mask NTP services that may conflict with chrony. Currently we are seeing the following failure: TASK ntp : Mask alternative NTP clients to prevent conflicts Could not find the requested service systemd-timesyncd.service: host The service_facts module shows that the service is not found: "systemd-timesyncd.service": { "name": "systemd-timesyncd.service", "source": "systemd", "state": "stopped", "status": "not-found" }, According to the Internet, this can happen if there are After/Before dependencies in one service on another that does not exist. This change fixes the handling of these not-found services to avoid the error. Story: 2009821 Task: 44401 Depends-On: https://review.opendev.org/c/openstack/kayobe/+/827404 Change-Id: I4b8a42704f2b0a145ee9dec433d91df67628cd9d --- ansible/roles/ntp/tasks/prepare.yml | 7 ++++++- releasenotes/notes/story-2009821-b309165e25e77aea.yaml | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/story-2009821-b309165e25e77aea.yaml diff --git a/ansible/roles/ntp/tasks/prepare.yml b/ansible/roles/ntp/tasks/prepare.yml index 5e365165a..cf4d82a74 100644 --- a/ansible/roles/ntp/tasks/prepare.yml +++ b/ansible/roles/ntp/tasks/prepare.yml @@ -4,7 +4,12 @@ - name: Mask alternative NTP clients to prevent conflicts vars: - service_exists: "{{ item in ansible_facts.services }}" + # NOTE(mgoddard): The service_facts module can return services that are not + # present, possibly due to After/Before dependencies in other services. + # These show up with a status of 'not-found'. + service_exists: >- + {{ item in ansible_facts.services and + ansible_facts.services[item].status != 'not-found' }} systemd: name: "{{ item }}" enabled: "{{ 'false' if service_exists else omit }}" diff --git a/releasenotes/notes/story-2009821-b309165e25e77aea.yaml b/releasenotes/notes/story-2009821-b309165e25e77aea.yaml new file mode 100644 index 000000000..8d4d2ea43 --- /dev/null +++ b/releasenotes/notes/story-2009821-b309165e25e77aea.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes an issue with masking NTP services which are not found. See `story + 2009821 `__ for details.