Fix NTP in check mode #68

Merged
gingermusketeer merged 1 commit from fix-ntp into main 2026-08-28 17:34:28 +00:00

This came up while setting up the nettside system for the first time. Before the change we saw the following error:

[ERROR]: Task failed: Module failed: Could not find the requested service systemd-timesyncd: host
Origin: /Users/maxbrosnahan/Projects/datakollektivet/systemer/common/roles/ntp/tasks/main.yaml:9:3

7
8 # Need to ensure that the following two services are restarted to be able to run `timedatectl show-timesync --all` ...
9 - name: Ensure systemd-timesyncd service is enabled and running
    ^ column 3

fatal: [test_node]: FAILED! => {"changed": false, "msg": "Could not find the requested service systemd-timesyncd: host"}

Now we see:

❯ uv run ansible-playbook --check --diff nettside/playbooks/site.yaml

PLAY [Setup NTP] *****************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [nettside]

TASK [ntp : Install systemd-timesyncd package] ***********************************************************************************************************************
The following NEW packages will be installed:
  systemd-timesyncd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
changed: [nettside]

TASK [ntp : Ensure systemd-timesyncd service is enabled and running] *************************************************************************************************
ok: [nettside]

TASK [ntp : Ensure systemd-timedated service is enabled and running] *************************************************************************************************
changed: [nettside]

TASK [ntp : Get NTP synchronization status] **************************************************************************************************************************
ok: [nettside]

TASK [ntp : Normalize NTP status] ************************************************************************************************************************************
ok: [nettside]

TASK [ntp : Report NTP synchronization status] ***********************************************************************************************************************
ok: [nettside] => {
    "msg": "NTP synchronization: Not syncing"
}

TASK [ntp : Verify NTP client is active] *****************************************************************************************************************************
skipping: [nettside]

PLAY RECAP ***********************************************************************************************************************************************************
nettside                   : ok=7    changed=2    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0

Additional testing

I have also tested a few combinations locally:

  1. --check --diff on a clean machine
  2. apply on a clean machine
    3.--check --diff on an existing machine
  3. apply on an existing machine
================================================================
 TEST 1: Check mode on Clean Machine
================================================================

PLAY [Test NTP Role] *************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Install systemd-timesyncd package] ***********************************************************************************************************************
The following NEW packages will be installed:
  systemd-timesyncd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
changed: [test_node]

TASK [ntp : Ensure systemd-timesyncd service is enabled and running] *************************************************************************************************
ok: [test_node]

TASK [ntp : Ensure systemd-timedated service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Get NTP synchronization status] **************************************************************************************************************************
ok: [test_node]

TASK [ntp : Normalize NTP status] ************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Report NTP synchronization status] ***********************************************************************************************************************
ok: [test_node] => {
    "msg": "NTP synchronization: Not syncing"
}

TASK [ntp : Verify NTP client is active] *****************************************************************************************************************************
skipping: [test_node]

PLAY RECAP ***********************************************************************************************************************************************************
test_node                  : ok=7    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0


================================================================
 TEST 2: Apply mode on Clean Machine
================================================================

PLAY [Test NTP Role] *************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Install systemd-timesyncd package] ***********************************************************************************************************************
changed: [test_node]

TASK [ntp : Ensure systemd-timesyncd service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Ensure systemd-timedated service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Get NTP synchronization status] **************************************************************************************************************************
ok: [test_node]

TASK [ntp : Normalize NTP status] ************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Report NTP synchronization status] ***********************************************************************************************************************
ok: [test_node] => {
    "msg": "NTP synchronization: Syncing"
}

TASK [ntp : Verify NTP client is active] *****************************************************************************************************************************
ok: [test_node] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ***********************************************************************************************************************************************************
test_node                  : ok=8    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

==> [PASS] Apply completed successfully.

================================================================
 TEST 3: Check mode on Existing Machine
================================================================

PLAY [Test NTP Role] *************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Install systemd-timesyncd package] ***********************************************************************************************************************
ok: [test_node]

TASK [ntp : Ensure systemd-timesyncd service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Ensure systemd-timedated service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Get NTP synchronization status] **************************************************************************************************************************
ok: [test_node]

TASK [ntp : Normalize NTP status] ************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Report NTP synchronization status] ***********************************************************************************************************************
ok: [test_node] => {
    "msg": "NTP synchronization: Syncing"
}

TASK [ntp : Verify NTP client is active] *****************************************************************************************************************************
skipping: [test_node]

PLAY RECAP ***********************************************************************************************************************************************************
test_node                  : ok=7    changed=2    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

==> [PASS] Check mode on existing machine succeeded with zero unexpected errors.

================================================================
 TEST 4: Apply mode on Existing Machine (Idempotency)
================================================================

PLAY [Test NTP Role] *************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Install systemd-timesyncd package] ***********************************************************************************************************************
ok: [test_node]

TASK [ntp : Ensure systemd-timesyncd service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Ensure systemd-timedated service is enabled and running] *************************************************************************************************
changed: [test_node]

TASK [ntp : Get NTP synchronization status] **************************************************************************************************************************
ok: [test_node]

TASK [ntp : Normalize NTP status] ************************************************************************************************************************************
ok: [test_node]

TASK [ntp : Report NTP synchronization status] ***********************************************************************************************************************
ok: [test_node] => {
    "msg": "NTP synchronization: Syncing"
}

TASK [ntp : Verify NTP client is active] *****************************************************************************************************************************
ok: [test_node] => {
    "changed": false,
    "msg": "All assertions passed"
}

PLAY RECAP ***********************************************************************************************************************************************************
test_node                  : ok=8    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

This came up while setting up the nettside system for the first time. Before the change we saw the following error: ``` [ERROR]: Task failed: Module failed: Could not find the requested service systemd-timesyncd: host Origin: /Users/maxbrosnahan/Projects/datakollektivet/systemer/common/roles/ntp/tasks/main.yaml:9:3 7 8 # Need to ensure that the following two services are restarted to be able to run `timedatectl show-timesync --all` ... 9 - name: Ensure systemd-timesyncd service is enabled and running ^ column 3 fatal: [test_node]: FAILED! => {"changed": false, "msg": "Could not find the requested service systemd-timesyncd: host"} ``` Now we see: ``` ❯ uv run ansible-playbook --check --diff nettside/playbooks/site.yaml PLAY [Setup NTP] ***************************************************************************************************************************************************** TASK [Gathering Facts] *********************************************************************************************************************************************** ok: [nettside] TASK [ntp : Install systemd-timesyncd package] *********************************************************************************************************************** The following NEW packages will be installed: systemd-timesyncd 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. changed: [nettside] TASK [ntp : Ensure systemd-timesyncd service is enabled and running] ************************************************************************************************* ok: [nettside] TASK [ntp : Ensure systemd-timedated service is enabled and running] ************************************************************************************************* changed: [nettside] TASK [ntp : Get NTP synchronization status] ************************************************************************************************************************** ok: [nettside] TASK [ntp : Normalize NTP status] ************************************************************************************************************************************ ok: [nettside] TASK [ntp : Report NTP synchronization status] *********************************************************************************************************************** ok: [nettside] => { "msg": "NTP synchronization: Not syncing" } TASK [ntp : Verify NTP client is active] ***************************************************************************************************************************** skipping: [nettside] PLAY RECAP *********************************************************************************************************************************************************** nettside : ok=7 changed=2 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0 ``` ## Additional testing I have also tested a few combinations locally: 1. `--check --diff` on a clean machine 2. `apply` on a clean machine 3.`--check --diff` on an existing machine 2. `apply` on an existing machine ``` ================================================================ TEST 1: Check mode on Clean Machine ================================================================ PLAY [Test NTP Role] ************************************************************************************************************************************************* TASK [Gathering Facts] *********************************************************************************************************************************************** ok: [test_node] TASK [ntp : Install systemd-timesyncd package] *********************************************************************************************************************** The following NEW packages will be installed: systemd-timesyncd 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. changed: [test_node] TASK [ntp : Ensure systemd-timesyncd service is enabled and running] ************************************************************************************************* ok: [test_node] TASK [ntp : Ensure systemd-timedated service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Get NTP synchronization status] ************************************************************************************************************************** ok: [test_node] TASK [ntp : Normalize NTP status] ************************************************************************************************************************************ ok: [test_node] TASK [ntp : Report NTP synchronization status] *********************************************************************************************************************** ok: [test_node] => { "msg": "NTP synchronization: Not syncing" } TASK [ntp : Verify NTP client is active] ***************************************************************************************************************************** skipping: [test_node] PLAY RECAP *********************************************************************************************************************************************************** test_node : ok=7 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 ================================================================ TEST 2: Apply mode on Clean Machine ================================================================ PLAY [Test NTP Role] ************************************************************************************************************************************************* TASK [Gathering Facts] *********************************************************************************************************************************************** ok: [test_node] TASK [ntp : Install systemd-timesyncd package] *********************************************************************************************************************** changed: [test_node] TASK [ntp : Ensure systemd-timesyncd service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Ensure systemd-timedated service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Get NTP synchronization status] ************************************************************************************************************************** ok: [test_node] TASK [ntp : Normalize NTP status] ************************************************************************************************************************************ ok: [test_node] TASK [ntp : Report NTP synchronization status] *********************************************************************************************************************** ok: [test_node] => { "msg": "NTP synchronization: Syncing" } TASK [ntp : Verify NTP client is active] ***************************************************************************************************************************** ok: [test_node] => { "changed": false, "msg": "All assertions passed" } PLAY RECAP *********************************************************************************************************************************************************** test_node : ok=8 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ==> [PASS] Apply completed successfully. ================================================================ TEST 3: Check mode on Existing Machine ================================================================ PLAY [Test NTP Role] ************************************************************************************************************************************************* TASK [Gathering Facts] *********************************************************************************************************************************************** ok: [test_node] TASK [ntp : Install systemd-timesyncd package] *********************************************************************************************************************** ok: [test_node] TASK [ntp : Ensure systemd-timesyncd service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Ensure systemd-timedated service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Get NTP synchronization status] ************************************************************************************************************************** ok: [test_node] TASK [ntp : Normalize NTP status] ************************************************************************************************************************************ ok: [test_node] TASK [ntp : Report NTP synchronization status] *********************************************************************************************************************** ok: [test_node] => { "msg": "NTP synchronization: Syncing" } TASK [ntp : Verify NTP client is active] ***************************************************************************************************************************** skipping: [test_node] PLAY RECAP *********************************************************************************************************************************************************** test_node : ok=7 changed=2 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 ==> [PASS] Check mode on existing machine succeeded with zero unexpected errors. ================================================================ TEST 4: Apply mode on Existing Machine (Idempotency) ================================================================ PLAY [Test NTP Role] ************************************************************************************************************************************************* TASK [Gathering Facts] *********************************************************************************************************************************************** ok: [test_node] TASK [ntp : Install systemd-timesyncd package] *********************************************************************************************************************** ok: [test_node] TASK [ntp : Ensure systemd-timesyncd service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Ensure systemd-timedated service is enabled and running] ************************************************************************************************* changed: [test_node] TASK [ntp : Get NTP synchronization status] ************************************************************************************************************************** ok: [test_node] TASK [ntp : Normalize NTP status] ************************************************************************************************************************************ ok: [test_node] TASK [ntp : Report NTP synchronization status] *********************************************************************************************************************** ok: [test_node] => { "msg": "NTP synchronization: Syncing" } TASK [ntp : Verify NTP client is active] ***************************************************************************************************************************** ok: [test_node] => { "changed": false, "msg": "All assertions passed" } PLAY RECAP *********************************************************************************************************************************************************** test_node : ok=8 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ```
luisa approved these changes 2026-08-28 16:54:44 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
datakollektivet/systemer!68
No description provided.