ansible-playbook 一键部署ntp时间同步 yml


---  
- 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
 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM