From f48418655de11512d54f596c516dbdb101f6d925 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 28 Nov 2020 00:23:57 +0100 Subject: core/ntp: add support for openbsd --- roles/core/ntp/handlers/main.yml | 5 +++++ roles/core/ntp/tasks/Debian_chrony.yml | 11 +++++++++++ roles/core/ntp/tasks/Debian_openntpd.yml | 11 +++++++++++ roles/core/ntp/tasks/Debian_systemd-timesyncd.yml | 18 ++++++++++++++++++ roles/core/ntp/tasks/OpenBSD_openntpd.yml | 6 ++++++ roles/core/ntp/tasks/chrony.yml | 11 ----------- roles/core/ntp/tasks/error.yml | 3 +++ roles/core/ntp/tasks/main.yml | 15 ++++++++++++--- roles/core/ntp/tasks/openntpd.yml | 11 ----------- roles/core/ntp/tasks/systemd-timesyncd.yml | 18 ------------------ roles/core/ntp/templates/openntpd.conf.j2 | 2 ++ 11 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 roles/core/ntp/tasks/Debian_chrony.yml create mode 100644 roles/core/ntp/tasks/Debian_openntpd.yml create mode 100644 roles/core/ntp/tasks/Debian_systemd-timesyncd.yml create mode 100644 roles/core/ntp/tasks/OpenBSD_openntpd.yml delete mode 100644 roles/core/ntp/tasks/chrony.yml create mode 100644 roles/core/ntp/tasks/error.yml delete mode 100644 roles/core/ntp/tasks/openntpd.yml delete mode 100644 roles/core/ntp/tasks/systemd-timesyncd.yml (limited to 'roles/core') diff --git a/roles/core/ntp/handlers/main.yml b/roles/core/ntp/handlers/main.yml index 0f11a5da..fa1274e8 100644 --- a/roles/core/ntp/handlers/main.yml +++ b/roles/core/ntp/handlers/main.yml @@ -13,3 +13,8 @@ service: name: openntpd state: restarted + +- name: restart ntpd + service: + name: ntpd + state: restarted diff --git a/roles/core/ntp/tasks/Debian_chrony.yml b/roles/core/ntp/tasks/Debian_chrony.yml new file mode 100644 index 00000000..d220af30 --- /dev/null +++ b/roles/core/ntp/tasks/Debian_chrony.yml @@ -0,0 +1,11 @@ +--- +- name: install chrony + apt: + name: chrony + state: present + +- name: install chrony configuration + template: + src: chrony.conf.j2 + dest: /etc/chrony/chrony.conf + notify: restart chrony diff --git a/roles/core/ntp/tasks/Debian_openntpd.yml b/roles/core/ntp/tasks/Debian_openntpd.yml new file mode 100644 index 00000000..76f62646 --- /dev/null +++ b/roles/core/ntp/tasks/Debian_openntpd.yml @@ -0,0 +1,11 @@ +--- +- name: install openntpd + apt: + name: openntpd + state: present + +- name: install openntpd configuration + template: + src: openntpd.conf.j2 + dest: /etc/openntpd/ntpd.conf + notify: restart openntpd diff --git a/roles/core/ntp/tasks/Debian_systemd-timesyncd.yml b/roles/core/ntp/tasks/Debian_systemd-timesyncd.yml new file mode 100644 index 00000000..20a5f379 --- /dev/null +++ b/roles/core/ntp/tasks/Debian_systemd-timesyncd.yml @@ -0,0 +1,18 @@ +--- +- name: set ntp servers + when: + - ntp_client is defined + - "'servers' in ntp_client" + lineinfile: + path: /etc/systemd/timesyncd.conf + regexp: '^#?NTP=' + line: "NTP={{ ntp_client.servers | map(attribute='name') | join(' ') }}" + notify: restart systemd-timesyncd + +- name: un-set ntp servers + when: "ntp_client is not defined or 'servers' not in ntp_client" + lineinfile: + path: /etc/systemd/timesyncd.conf + regexp: '^#?NTP=' + line: "#NTP=" + notify: restart systemd-timesyncd diff --git a/roles/core/ntp/tasks/OpenBSD_openntpd.yml b/roles/core/ntp/tasks/OpenBSD_openntpd.yml new file mode 100644 index 00000000..947b23c4 --- /dev/null +++ b/roles/core/ntp/tasks/OpenBSD_openntpd.yml @@ -0,0 +1,6 @@ +--- +- name: install openntpd configuration + template: + src: openntpd.conf.j2 + dest: /etc/ntpd.conf + notify: restart ntpd diff --git a/roles/core/ntp/tasks/chrony.yml b/roles/core/ntp/tasks/chrony.yml deleted file mode 100644 index d220af30..00000000 --- a/roles/core/ntp/tasks/chrony.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: install chrony - apt: - name: chrony - state: present - -- name: install chrony configuration - template: - src: chrony.conf.j2 - dest: /etc/chrony/chrony.conf - notify: restart chrony diff --git a/roles/core/ntp/tasks/error.yml b/roles/core/ntp/tasks/error.yml new file mode 100644 index 00000000..84a1a198 --- /dev/null +++ b/roles/core/ntp/tasks/error.yml @@ -0,0 +1,3 @@ +--- +- fail: + msg: "ntp variant '{{ ntp_variant }}' is not supported on this platform" diff --git a/roles/core/ntp/tasks/main.yml b/roles/core/ntp/tasks/main.yml index 77f281ff..d8c619a9 100644 --- a/roles/core/ntp/tasks/main.yml +++ b/roles/core/ntp/tasks/main.yml @@ -1,5 +1,14 @@ --- -## TODO: make this work on openbsd and debian/ubuntu -- name: run ntp-variant specific tasks +- name: load os/distrubtion/version specific tasks when: ntp_variant is defined - include_tasks: "{{ ntp_variant }}.yml" + vars: + params: + files: + - "{{ ansible_distribution_release }}_{{ ntp_variant }}.yml" + - "{{ ansible_distribution }}_{{ ntp_variant }}.yml" + - "{{ ansible_os_family }}_{{ ntp_variant }}.yml" + - "error.yml" + loop: "{{ q('first_found', params) }}" + loop_control: + loop_var: tasks_file + include_tasks: "{{ tasks_file }}" diff --git a/roles/core/ntp/tasks/openntpd.yml b/roles/core/ntp/tasks/openntpd.yml deleted file mode 100644 index 76f62646..00000000 --- a/roles/core/ntp/tasks/openntpd.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: install openntpd - apt: - name: openntpd - state: present - -- name: install openntpd configuration - template: - src: openntpd.conf.j2 - dest: /etc/openntpd/ntpd.conf - notify: restart openntpd diff --git a/roles/core/ntp/tasks/systemd-timesyncd.yml b/roles/core/ntp/tasks/systemd-timesyncd.yml deleted file mode 100644 index 20a5f379..00000000 --- a/roles/core/ntp/tasks/systemd-timesyncd.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -- name: set ntp servers - when: - - ntp_client is defined - - "'servers' in ntp_client" - lineinfile: - path: /etc/systemd/timesyncd.conf - regexp: '^#?NTP=' - line: "NTP={{ ntp_client.servers | map(attribute='name') | join(' ') }}" - notify: restart systemd-timesyncd - -- name: un-set ntp servers - when: "ntp_client is not defined or 'servers' not in ntp_client" - lineinfile: - path: /etc/systemd/timesyncd.conf - regexp: '^#?NTP=' - line: "#NTP=" - notify: restart systemd-timesyncd diff --git a/roles/core/ntp/templates/openntpd.conf.j2 b/roles/core/ntp/templates/openntpd.conf.j2 index 09a6a9c3..3e2204f6 100644 --- a/roles/core/ntp/templates/openntpd.conf.j2 +++ b/roles/core/ntp/templates/openntpd.conf.j2 @@ -1,3 +1,4 @@ +{% if ntp_client is defined %} ### Client {% if 'servers' in ntp_client %} @@ -11,6 +12,7 @@ server {{ server.name }}{% if 'options' in server %} {{ server.options }}{% endi servers {{ pool.name }}{% if 'options' in pool %} {{ pool.options }}{% endif %}{{ '' }} {% endfor %} {% endif %} +{% endif %} {% if ntp_server is defined %} -- cgit v1.2.3