Next up, we are copying the ntp.conf file from the templates folder, adding the list of NTP servers as we do, and then telling Ansible to restart NTP whenever the configuration file changes:
- name: copy the ntp.conf to /etc/ntp.conf template: src: "ntp.conf.j2" dest: "/etc/ntp.conf" notify: "restart ntp"
The template file can be found at roles/common/templates/ntp.conf.j2:
# {{ ansible_managed }}driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1 restrict ::1{% for item in ntp_servers %}server {{ item }} iburst{% endfor %}includefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor
As you can see, we are using the ntp_servers variable; this is stored in the roles/common/defaults/main.yml ...