패턴은 ntpq -p에서
remote refid st t when poll reach delay offset jitter
==============================================================================
0.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.ubuntu.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
-send.mx.cdnetwo 125.185.190.74 2 u 58 64 377 1.035 -2.002 1.485
*121.162.54.1 13.209.84.50 3 u 60 64 377 2.872 1.390 0.772
+121.174.142.82 220.73.142.66 3 u 58 64 377 8.309 -3.675 1.064
+mail.innotab.co 13.209.84.50 3 u 55 64 377 2.898 -2.468 0.951
-121.174.142.81 220.73.142.66 3 u 59 64 377 7.741 -1.928 1.586
+121.174.142.82 220.73.142.66 3 u 58 64 377 8.309 -3.675 1.06
-121.174.142.81 220.73.142.66 3 u 59 64 377 7.741 -1.928 1.586
요부분 오프셋 추출
응용해서 사용하길
---
- name: Get NTP offset values from remote servers
hosts: your_remote_servers # 특정 원격 서버의 호스트 그룹 또는 호스트명으로 변경해주세요.
gather_facts: yes
tasks:
- name: Get NTP offset from remote servers
shell: "ntpq -p | awk '/^[+-]?[0-9]+\\.[0-9]+/ { print $9 }'"
register: ntp_offsets_raw
- name: Extract NTP offset values
set_fact:
ntp_offsets: "{{ ntp_offsets_raw.stdout_lines | select('match', '^[+-]?[0-9]+\\.[0-9]+') | map('float') | list }}"
when: ntp_offsets_raw.stdout_lines is defined
- name: Save NTP offset to file
block:
- name: Save NTP offset to file with two values
copy:
content: |
{% if ntp_offsets | length >= 1 %}
off1={{ ntp_offsets[0] }}
{% endif %}
{% if ntp_offsets | length >= 2 %}
off2={{ ntp_offsets[1] }}
{% endif %}
dest: /home/ansible/result.txt
when: ntp_offsets | length >= 1
'나는 노동자 > 이런저런 Tip' 카테고리의 다른 글
IIS FILE HTTP 오류 404.3 - Not Found (0) | 2023.12.12 |
---|---|
iPhone 강제로 재시동하기 (0) | 2023.11.03 |
미드저니 기본 명령어 (0) | 2023.05.13 |
windows os hostname s/n ip (0) | 2023.03.20 |
grafana plugin 수동설치 (0) | 2023.03.03 |