微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
 

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐