Hello Guys,
I know you have been waiting for a automation which can help to sync the time of windows server/Desktop to local NTP server using ansible
In the previous blog i have shared a playbook how you can use it to setup a NTP server on rhel or centos box in this will be using a playbook to connect with windows client to sync them with local ntp server.
so here is the playbook
---
- name: Configure NTP server on Windows and synchronize time
hosts: all
#become: yes
force_handlers: True
gather_facts: false
tasks:
# - name: Install NTP service
# win_feature:
# name: NTP
# state: present
##This step is not necessary but added for asthetics so ip is not shown but fqdn looks more appling
- name: Configure NTP server on windows host
ansible.builtin.copy:
dest: C:\Windows\System32\drivers\etc\hosts
content: |
{{ ntp_server }} rhel.ntpserver.local
# notify:
# - restart ntpd
- name: Synchronize time with NTP server
ansible.windows.win_powershell:
script: |
w32tm /config /manualpeerlist:"rhel.ntpserver.local" /syncfromflags:manual /reliable:YES
w32tm /resync
notify:
- restart w32time
ignore_errors: true
handlers:
# - name: restart ntpd
# win_service:
# name: ntpd
# state: restarted
- name: restart w32time
win_service:
name: w32time
state: restarted
to run the ansible playbook
ansible-playbook -i inventory_file ntp_client.yml -e ntp_server = "ip address of ntpserver"
Enjoy and let me know what automation you want to work on...
No comments:
Post a Comment