From 26f6adb53bbe2d4e43f1745122523c2e175e5451 Mon Sep 17 00:00:00 2001 From: rubenb Date: Mon, 23 Oct 2023 13:46:57 +0200 Subject: [PATCH] add ntp playbook and roles --- linux-base-config-debian.yaml | 5 +++++ linux-config-ntp.yaml | 12 ++++++++++++ roles/config-ntp/files/timesync | 8 ++++++++ roles/config-ntp/handlers/main.yaml | 5 +++++ roles/config-ntp/tasks/main.yaml | 24 ++++++++++++++++++++++++ roles/config-ntp/vars/main.yaml | 4 ++++ 6 files changed, 58 insertions(+) create mode 100644 linux-config-ntp.yaml create mode 100644 roles/config-ntp/files/timesync create mode 100644 roles/config-ntp/handlers/main.yaml create mode 100644 roles/config-ntp/tasks/main.yaml create mode 100644 roles/config-ntp/vars/main.yaml diff --git a/linux-base-config-debian.yaml b/linux-base-config-debian.yaml index b3ab7bd..dfc77da 100644 --- a/linux-base-config-debian.yaml +++ b/linux-base-config-debian.yaml @@ -42,6 +42,11 @@ name: config-server-type tags: config-server-type_config + - name: "[CONFIG NTP] Install and configure ntp" + import_role: + name: config-ntp + tags: config-ntp_config + #handlers: # - include_tasks: roles/{{ item }}/handlers/main.yaml # with_items: diff --git a/linux-config-ntp.yaml b/linux-config-ntp.yaml new file mode 100644 index 0000000..1441de3 --- /dev/null +++ b/linux-config-ntp.yaml @@ -0,0 +1,12 @@ +--- + +- hosts: "{{ ip_addr }}" + become: yes + become_method: sudo + gather_facts: yes + + tasks: + + - name: "[CONFIG NTP] Install and configure ntp" + import_role: + name: config-ntp diff --git a/roles/config-ntp/files/timesync b/roles/config-ntp/files/timesync new file mode 100644 index 0000000..7d47001 --- /dev/null +++ b/roles/config-ntp/files/timesync @@ -0,0 +1,8 @@ +#!/bin/sh +# PLS do NOT delete timesyncing from VM virtuals +# it is necessary for critical cluster services +# nada + +test -x /usr/sbin/ntpdate || exit 0 +/usr/sbin/ntpdate time1.verdnatura.es +/usr/sbin/ntpdate time2.verdnatura.es \ No newline at end of file diff --git a/roles/config-ntp/handlers/main.yaml b/roles/config-ntp/handlers/main.yaml new file mode 100644 index 0000000..c77652f --- /dev/null +++ b/roles/config-ntp/handlers/main.yaml @@ -0,0 +1,5 @@ +# restart crontab service to apply changes +- name: restart crontab hourly + service: + name: "{{ cron_daemon }}" + state: restarted \ No newline at end of file diff --git a/roles/config-ntp/tasks/main.yaml b/roles/config-ntp/tasks/main.yaml new file mode 100644 index 0000000..a1074d4 --- /dev/null +++ b/roles/config-ntp/tasks/main.yaml @@ -0,0 +1,24 @@ +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# Install and configure NTP +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# paso1 +# install package ntpdate +- name: install package ntpdate + apt: + name: "{{ ntpdate_package }}" + state: present +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +# paso2 +# copy timesync file to crontab.hourly +- name: copy file nslcd.conf + copy: + src: timesync + dest: "{{ timesync_path }}" + owner: root + group: root + mode: '0644' + backup: yes + notify: restart crontab hourly +#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \ No newline at end of file diff --git a/roles/config-ntp/vars/main.yaml b/roles/config-ntp/vars/main.yaml new file mode 100644 index 0000000..74a621e --- /dev/null +++ b/roles/config-ntp/vars/main.yaml @@ -0,0 +1,4 @@ +# vars file +ntpdate_package: ntpdate +timesync_path: /etc/cron.hourly/timesync +cron_daemon: cron \ No newline at end of file