熟练掌握 roles
熟练掌握 playbook 写法
熟练掌握ansible-playbook 用法
二、效果
批量添加不同频次的ntp时间同步服务
三、ansible的实现过程
1. 执行命令
[root@AutomaticTool AutomaticTool]# ansible-playbook init.yml
2. 目录结构
[root@AutomaticTool AutomaticTool]# tree roles/common/
roles/common/
├── files
│ ├── HistoryRecord.sh
└── tasks
├── main.yml
└── ntp.yml
2 directories, 3 files
3. 代码实现
init.yml
[root@AutomaticTool AutomaticTool]# cat init.yml
---
# This playbook deploys the whole application stack in this site.
- hosts: ALLHOSTS
remote_user: root
roles:
- { role: common , tags: [ 'EnvInit' ] }
main.yml
---
- include: ntp.yml
ntp.yml
[root@AutomaticTool tasks]# cat ntp.yml
---
- name: ntp update (Crontab)
cron:
name: "ntp time sync Added by stanley 20180420 - Frequency: {{ item.Times }}"
minute: "{{ item.Times }}"
job: "{{ item.Server }}"
state: present
with_items:
- { Server: "ntpdate -u ntpserver1.com" , Times: "*/10" }
- { Server: "ntpdate -u ntpserver2.com" , Times: "*/20" }
- { Server: "ntpdate -u ntpserver3.com" , Times: "*/30" }
^0^ OVER, So Easy 吧。。
执行完命令后就可以为想要的机器添加不同的频次的时间同步服务啦。
具体效果如文始图啦。