1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| [root@localhost ~]# vim check_time.sh #!/bin/bash
#对时 # 关闭防火墙 #systemctl stop firewalld #setenforce 0 # 下载软件 yum -y instal ntpdate # 查看当前时区 timedatectl # 列出可用时区 #timedatectl list-timezones # 修改上海时区 timedatectl set-timezone Asia/Shanghai # 验证修改是否生效 timedatectl # 对时 ntpdate ntp.aliyun.com echo "对时成功,当前时间为:" date +'%F %H:%M:%S'
# 定义主机组 [root@k8s-master ~]# vim time [all] 10.100.40.252 10.100.40.253 10.100.40.254
# 配置yaml文件 [root@k8s-master ~]# vim time.yaml --- - name: 更新 time hosts: all become: yes tasks: - name: copy time script to remote host copy: src: /root/check_time.sh dest: /root/check_time.sh owner: root group: root mode: 0755
- name: execute time script shell: bash /root/check_time.sh args: chdir: /root
# 启动命令 ansible-playbook -i /root/time time.yaml
|