shalomb / ansible-systemd-timesyncd

Ansible role to configure systemd-timesyncd's NTP and timezone parameters
9 stars 1 forks source link

"Assert systemd-timesyncd status" task fails #5

Open jantari opened 2 years ago

jantari commented 2 years ago

I have noticed that the task "timesyncd : Assert systemd-timesyncd status" from https://github.com/shalomb/ansible-systemd-timesyncd/blob/f5db2260a069c3d5d82b6723d226bf52f8cbe705/tasks/tests.yml#L32 fails on one of my hosts with the following error:

failed: [machine] (item={'regex': 'Started Network Time Synchronization', 'fail_msg': 'systemd-timesyncd does not appear to have started NTP Synchronization'}) => changed=false 
  ansible_loop_var: item
  assertion: timesyncd_status.stdout | regex_search("Started Network Time Synchronization")
  evaluated_to: false
  item:
    fail_msg: systemd-timesyncd does not appear to have started NTP Synchronization
    regex: Started Network Time Synchronization
  msg: systemd-timesyncd does not appear to have started NTP Synchronization

The output of sudo systemctl status systemd-timesyncd on the machine is:

● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-11-30 00:13:23 CET; 3 weeks 1 days ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 420 (systemd-timesyn)
     Status: "Initial synchronization to time server INTERNAL_IP:123 (INTERNAL_IP)."
      Tasks: 2 (limit: 4557)
     Memory: 1.3M
     CGroup: /system.slice/systemd-timesyncd.service
             └─420 /lib/systemd/systemd-timesyncd

Warning: journal has been rotated since unit was started, output may be incomplete.

everything is operating fine and yet the task asserts a failure. Perhaps it is not the most robust technique to try and regex-scrape the output of a shell command to try and look for logs of a service? I personally think this test can be removed.

ArturFormella commented 2 years ago

My workaround:

  pre_tasks:
    # https://github.com/shalomb/ansible-systemd-timesyncd/issues/5
    - name: Repair ansible-systemd-timesyncd
      ignore_errors: yes
      become: yes
      ansible.builtin.shell: |
        timedatectl set-ntp false
        timedatectl set-ntp true

 roles:
    - role: ansible-systemd-timesyncd
      become: yes
      config:
        ntp_servers:
          - ...
        timezone: '...'