Making use of the redhat.rhel_system_roles collection installed in another item create a playbook called /home/student/ansible/timesync.yml that:
Runs on all managed nodes
Uses the timesync role
Configures the role to use the currently active NTP provider
Configures the role to use the time server 172.25.250.15
Configures the role to enable the iburst parameter
【題前說明】
這題開始要用到roles了,而且也呼應前面第三題,萬一前面做不出來,這題當然也就報銷了。簡單來說,就是把collections裡面的timesyc roles複製到家目錄下剛新建的的roles裡面,然後讓ansible使用它,為每一台node部署校時的chronyd,跟Data主機作時間校對。
一.解題過程:
1.建立timesyc.yml
[student@workstation ansible]$ touch timesync.yml
[student@workstation ansible]$ cd roles/
[student@workstation ansible]$ cd roles/
2.複製collections裡面的timesyc到家目錄下剛新建的的roles裡面,並開始編輯
[student@workstation ansible]$ cp -r /home/student/ansible/mycollections/ansible_collections/fedora/linux_system_roles/roles/timesync .\\把mycollections內的角色複製到roles下面準備使用
[student@workstation ansible]$ ll
[student@workstation ansible]$ vim timesync.yml
[student@workstation ansible]$ vim timesync.yml
---- name: use chronyd
hosts: all
vars:
timesync_ntp_servers:
- hostname: 172.25.250.15
iburst: yes
roles:
- timesync
二.驗證結果
[student@workstation ansible]$ ansible-playbook -C timesync.yml \\試跑看看是否正常
[student@workstation ansible]$ ansible-playbook timesync.yml \\沒問題就正式跑
[student@workstation ansible]$ ansible all -m shell -a 'chronyc sources -v' \\驗證校時是否正常
[student@workstation ansible]$ ansible all -m shell -a 'systemctl status chronyd'
三.恢復解題前的環境
把chronyd校時的功能從每一台node上移除。
[student@workstation ansible]$ vim 05-lab-timesync-stop.yml
---
- name: recover chrony.conf back to default
hosts: all
tasks:
- name: recover chrony.conf back to default
copy:
src: /etc/chrony.conf
dest: /etc/chrony.conf
- name: remove chronyd
yum:
name: chrony
state: absent
- name: remove role timesync
hosts: 127.0.0.1
tasks:
- name: remove role timesync
shell: ansible-galaxy remove timesync
- name: remove rhel-system-roles
yum:
name: rhel-system-roles
state: absent
- name: remove timesync file and roles directory
hosts: 127.0.0.1
tasks:
- name: remove timesync file
file:
path: /home/student/ansible/timesync.yml
state: absent
- name:
file:
path: /home/student/ansible/roles
[student@workstation ansible]$ ansible-playbook 05-lab-timesync-stop.yml
沒有留言:
張貼留言