a5.ansible 生产实战案例 -- chrony客户端playbook
2023-09-14 09:15:22 时间
chrony客户端playbook
源码下载地址:https://github.com/raymond999999/ansible
[root@ansible-server ansible]# cd playbook/chrony
[root@ansible-server chrony]# vars.yml
SERVER1: 172.31.0.101
SERVER2: 172.31.0.104
[root@ansible-server chrony]# vim install_chrony_client.yml
---
- hosts: chronyclient
vars_files:
vars.yml
tasks:
- name: install CentOS or Rocky chrony
yum:
name: chrony
when:
- (ansible_distribution=="CentOS" or ansible_distribution=="Rocky")
- name: delete CentOS or Rocky /etc/chrony.conf file contains '^pool.*' string line
lineinfile:
path: /etc/chrony.conf
regexp: '^pool.*'
state: absent
when:
- (ansible_distribution=="CentOS" or ansible_distribution=="Rocky")
notify:
- restart chronyd
- name: delete CentOS or Rocky /etc/chrony.conf file contains '^server.*' string line
lineinfile:
path: /etc/chrony.conf
regexp: '^server.*'
state: absent
when:
- (ansible_distribution=="CentOS" or ansible_distribution=="Rocky")
notify:
- restart chronyd
- name: add Time server for CentOS or Rocky /etc/chrony.conf file
lineinfile:
path: /etc/chrony.conf
insertafter: '^# Please consider .*'
line: "server {{ SERVER1 }} iburst\nserver {{ SERVER2 }} iburst"
when:
- (ansible_distribution=="CentOS" or ansible_distribution=="Rocky")
notify:
- restart chronyd
- name: delete lock files
file:
path: "{{ item }}"
state: absent
loop:
- /var/lib/dpkg/lock
- /var/lib/apt/lists/lock
- /var/cache/apt/archives/lock
when:
- ansible_distribution=="Ubuntu"
- name: apt update
apt:
update_cache: yes
force: yes
when:
- ansible_distribution=="Ubuntu"
- name: install Ubuntu chrony
apt:
name: chrony
force: yes
when:
- ansible_distribution=="Ubuntu"
- name: delete Ubuntu /etc/chrony/chrony.conf file contains '^pool.*' string line
lineinfile:
path: /etc/chrony/chrony.conf
regexp: '^pool.*'
state: absent
when:
- ansible_distribution=="Ubuntu"
notify:
- restart chronyd
- name: add Time server for Ubuntu /etc/chrony/chrony.conf file
lineinfile:
path: /etc/chrony/chrony.conf
insertafter: '^# See http:.*'
line: "server {{ SERVER1 }} iburst\nserver {{ SERVER2 }} iburst"
when:
- ansible_distribution=="Ubuntu"
notify:
- restart chronyd
- name: start chronyd
systemd:
name: chronyd
state: started
enabled: yes
handlers:
- name: restart chronyd
service:
name: chronyd
state: restarted
[root@ansible-server chrony]# cd ../../
[root@ansible-server ansible]# ansible-playbook playbook/chrony/install_chrony_client.yml
PLAY [chronyclient] ***************************************************************************************************************************
TASK [Gathering Facts] ************************************************************************************************************************
ok: [172.31.0.103]
ok: [172.31.0.105]
ok: [172.31.0.102]
TASK [install CentOS or Rocky chrony] *********************************************************************************************************
skipping: [172.31.0.105]
changed: [172.31.0.103]
changed: [172.31.0.102]
TASK [delete CentOS or Rocky /etc/chrony.conf file contains '^pool.*' string line] ************************************************************
skipping: [172.31.0.105]
ok: [172.31.0.103]
changed: [172.31.0.102]
TASK [delete CentOS or Rocky /etc/chrony.conf file contains '^server.*' string line] **********************************************************
skipping: [172.31.0.105]
changed: [172.31.0.103]
ok: [172.31.0.102]
TASK [add Time server for CentOS or Rocky /etc/chrony.conf file] ******************************************************************************
skipping: [172.31.0.105]
changed: [172.31.0.103]
changed: [172.31.0.102]
TASK [delete lock files] **********************************************************************************************************************
skipping: [172.31.0.102] => (item=/var/lib/dpkg/lock)
skipping: [172.31.0.102] => (item=/var/lib/apt/lists/lock)
skipping: [172.31.0.102] => (item=/var/cache/apt/archives/lock)
skipping: [172.31.0.103] => (item=/var/lib/dpkg/lock)
skipping: [172.31.0.103] => (item=/var/lib/apt/lists/lock)
skipping: [172.31.0.103] => (item=/var/cache/apt/archives/lock)
changed: [172.31.0.105] => (item=/var/lib/dpkg/lock)
changed: [172.31.0.105] => (item=/var/lib/apt/lists/lock)
changed: [172.31.0.105] => (item=/var/cache/apt/archives/lock)
TASK [apt update] *****************************************************************************************************************************
skipping: [172.31.0.102]
skipping: [172.31.0.103]
changed: [172.31.0.105]
TASK [install Ubuntu chrony] ******************************************************************************************************************
skipping: [172.31.0.102]
skipping: [172.31.0.103]
changed: [172.31.0.105]
TASK [delete Ubuntu /etc/chrony/chrony.conf file contains '^pool.*' string line] **************************************************************
skipping: [172.31.0.102]
skipping: [172.31.0.103]
changed: [172.31.0.105]
TASK [add Time server for Ubuntu /etc/chrony/chrony.conf file] ********************************************************************************
skipping: [172.31.0.102]
skipping: [172.31.0.103]
changed: [172.31.0.105]
TASK [start chronyd] **************************************************************************************************************************
changed: [172.31.0.103]
ok: [172.31.0.105]
changed: [172.31.0.102]
RUNNING HANDLER [restart chronyd] *************************************************************************************************************
changed: [172.31.0.103]
changed: [172.31.0.105]
changed: [172.31.0.102]
PLAY RECAP ************************************************************************************************************************************
172.31.0.102 : ok=7 changed=5 unreachable=0 failed=0 skipped=5 rescued=0 ignored=0
172.31.0.103 : ok=7 changed=5 unreachable=0 failed=0 skipped=5 rescued=0 ignored=0
172.31.0.105 : ok=8 changed=6 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0
[root@centos8-client ~]# chronyc sources -nv
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 172.31.0.101 3 6 17 55 +708us[ +788us] +/- 28ms
^+ 172.31.0.104 3 6 17 55 -902us[ -902us] +/- 32ms
[root@centos7-client ~]# chronyc sources -nv
210 Number of sources = 2
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 172.31.0.101 3 6 17 9 -522us[ -526us] +/- 34ms
^+ 172.31.0.104 3 6 17 10 +590us[ +590us] +/- 35ms
root@ubuntu2004-client:~# chronyc sources -nv
210 Number of sources = 2
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 172.31.0.101 3 6 17 52 -483us[ -400us] +/- 33ms
^+ 172.31.0.104 3 6 17 52 +169us[ +252us] +/- 34ms
相关文章
- socket-WebSocket-HttpListener-TcpListener服务端客户端的具体使用案例
- Mybatis+mysql动态分页查询数据案例——工具类(MybatisUtil.java)
- 技术方案设计的方法论及案例分享
- wireshark 抓包整理———— 从一个小案例开始 [一]
- redis 简单整理——客户端案例分析[十八]
- Flink(23):Flink之Window案例二(基于数量的滚动和滑动窗口)
- Golang协程goroutine和管道channel结合案例
- vue学习:xmg vue学习笔记2/14代码案例
- NLP:自然语言处理技术近十年发展技术更迭的简介、案例之详细攻略(持续更新)daiding待更新
- DataScience:数据预处理/特征工程之两大类别特征、四大数据类型(数值型/类别型/字符串型/时间型简介、代码实现(数值型特征离散化/类别型特征编码数字化)、案例应用之详细攻略
- 〖Python 数据库开发实战 - Python与MySQL交互篇⑦〗- MySQL Connector模块的综合案例 2
- OpenCV-PyQT项目实战(7)项目案例03:鼠标框选
- a7.ansible 生产实战案例 -- chrony客户端roles