diff --git a/CHANGELOG b/CHANGELOG index ae8e5bc..a9fd5d8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * base: configure "/usr/X11R6" and "/usr/local" for servers that have a mount on it * base: we can chose to deploy or not utils files * base: reordering default variable file and deleting unused one +* base: use a template for ntp configuration to ease the management of the different cases ### Fixed diff --git a/roles/base/defaults/main.yml b/roles/base/defaults/main.yml index 67da1ef..99a881d 100644 --- a/roles/base/defaults/main.yml +++ b/roles/base/defaults/main.yml @@ -12,6 +12,7 @@ general_alert_email: "root@localhost" cron_root_path: "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" # ntp.yml +is_ntpd_server: false ntpd_servers: "ntp.evolix.net" # fstab.yml diff --git a/roles/base/handlers/main.yml b/roles/base/handlers/main.yml index ad2c3c2..5ad9161 100644 --- a/roles/base/handlers/main.yml +++ b/roles/base/handlers/main.yml @@ -32,7 +32,7 @@ args: warn: false -- name: reload ntp +- name: restart ntpd service: name: ntpd state: restarted diff --git a/roles/base/tasks/ntp.yml b/roles/base/tasks/ntp.yml index badb684..fecb4b1 100644 --- a/roles/base/tasks/ntp.yml +++ b/roles/base/tasks/ntp.yml @@ -1,31 +1,12 @@ --- -- name: "Retrieve ntpd.conf content" - command: cat ntpd.conf - args: - chdir: /etc/ - check_mode: false - changed_when: false - register: ntpd_conf - tags: - - ntp - -- name: "Empty ntpd.conf before customizing it" - file: - path: /etc/ntpd.conf - state: absent - when: ntpd_conf.stdout is not regex('^servers ' + ntpd_servers + '$') - tags: - - ntp - - name: "Customize ntpd conf" - lineinfile: - path: /etc/ntpd.conf - line: "servers {{ ntpd_servers }}" - create: true + template: + src: ntpd.conf.j2 + dest: /etc/ntpd.conf owner: root group: wheel mode: '0644' notify: - - reload ntp + - restart ntpd tags: - ntp diff --git a/roles/base/templates/ntpd.conf.j2 b/roles/base/templates/ntpd.conf.j2 new file mode 100644 index 0000000..e116682 --- /dev/null +++ b/roles/base/templates/ntpd.conf.j2 @@ -0,0 +1,4 @@ +{% if is_ntpd_server %} +listen on * +{% endif %} +servers {{ ntpd_servers }}