init commit

This commit is contained in:
2025-07-21 14:26:07 -05:00
commit 6a683a7a38
25 changed files with 635 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
- name: Check time synchronization using ntpdig (modern method)
hosts: all
become: true
gather_facts: false
vars:
ntp_check_target: "pool.ntp.org"
tasks:
- name: Remove legacy ntpdate package (if present)
apt:
name: ntpdate
state: absent
- name: Ensure ntpsec-ntpdate is installed (provides ntpdig)
apt:
name: ntpsec-ntpdate
state: present
update_cache: true
- name: Query time offset using ntpdig from {{ ntp_check_target }}
command: "ntpdig {{ ntp_check_target }}"
register: ntpdig_output
changed_when: false
failed_when: ntpdig_output.rc != 0
- name: Parse correct offset and error from ntpdig output
set_fact:
ntpdig_offset: "{{ ntpdig_output.stdout | regex_search('[+-][0-9]+\\.[0-9]+(?=\\s+\\+/-)', '\\0') | default('N/A') }}"
ntpdig_error: "{{ ntpdig_output.stdout | regex_search('\\+/-\\s+([0-9]+\\.[0-9]+)', '\\1') | default('N/A') }}"
- name: Show parsed ntpdig result
debug:
msg: |
[{{ inventory_hostname }}]
Offset: {{ ntpdig_offset }} sec
Estimated error: ±{{ ntpdig_error }} sec
Raw output:
{{ ntpdig_output.stdout_lines | join('\n') }}