Add NTP Sever to client with Ansible
##1## Login to Prometheus server, because ansible provisioning from this server
Go to directory /home/ops/.ansible/roles/ntp and edit, vi /tasks/main.yml
- name: Install required packages
apt:
state: present
pkg: “{{ harden_linux_required_packages }}”
retries: 2
delay: 5
tags:
- ntpdate
- name: Set Time to your Zone
shell: “timedatectl set-timezone Asia/Jakarta”
- name: Add NTP Server
lineinfile:
line: “{{ server_ntp_uii }}”
path: /etc/ntp.conf
- name: Restart NTP
service:
name=ntp
state=restarted
enabled=yes
- name: Comment ntp.conf
lineinfile:
dest: “/etc/ntp.conf”
regexp: “{{ item }}”
line: “{{ harden_linux_ntp_settings[item] }}”
state: “present”
with_items:
- “{{ harden_linux_ntp_settings | list }}”
tags:
- ntp
- name: Check NTP
command: “ntpq -ps”
register: is_inactive
- name: Print Status
debug:
var: is_inactive.stdout
##2## Add ip host /etc/ansible/hosts , vi /etc/ansible/hosts
You can create group if you manage many host,
Define username, password nodes, and ssh port, you can refer to image below,
##3## go to directory /home/ops/.ansible/roles/ntp and edit vi ntp.yml
Hosts are group that we define earlier
Become its mean we become sudo user,
Roles is role that role we create earlier
##4## Run ansible with
Ansible-playbook ntp.yml
Make sure the host has python installed