---  
- hosts: all
  any_errors_fatal: "{{ any_errors_fatal | default(true) }}"
  tasks:
    - name: yum install ntp
      yum:
        name: ntp
        state: present
      tags:
        - install_ntp
    
    - name: set timezone to Asia-Shanghai
      shell: /usr/bin/timedatectl set-timezone Asia/Shanghai
      tags:
        - set_timezone
        
    - name: remove lines in ntp.conf
      lineinfile:
        path: /etc/ntp.conf
        regexp: '^server'
        state: absent
      tags:
        - remove_ntpconf
    
    - name: add ntp servers to ntp.conf
      lineinfile:
        path: /etc/ntp.conf
        regexp: '^server'
        state: present
        line: |+
          server ntp1.aliyun.com prefer
          server ntp2.aliyun.com
      tags:
        - add_new_ntpconf
    
    - name: stop ntpd service
      systemd:
        name: ntpd
        daemon_reload: yes
        state: stopped
      tags:
        - stop__ntpd

    - name: manual sync time with ntpdate
      shell: /usr/sbin/ntpdate ntp1.aliyun.com
      tags:
        - manual_sync_datetime

    - name: enable and start ntpd
      systemd:
        name: ntpd
        daemon_reload: yes
        state: started
        enabled: yes
      tags:
        - enable_start_ntpd

    - name: Control whether NTP is enabled
      shell: /usr/bin/timedatectl set-ntp yes
      tags:
        - enable_ntp_control
 

 

相关文章:

  • 2021-10-30
  • 2022-01-01
  • 2022-12-23
猜你喜欢
  • 2021-06-21
  • 2021-12-09
  • 2021-12-25
  • 2021-12-25
  • 2022-12-23
  • 2021-12-26
  • 2021-08-28
相关资源
相似解决方案