Skip to content

Commit c0de803

Browse files
committed
update readme
1 parent 5fed4a4 commit c0de803

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,40 @@ Grafana dashboard可以使用[9964][25]
245245
- [Prometheus 监控 nginx][22]
246246
- [prometheus远端存储之VictoriaMetrics][23]
247247

248+
## 十二、资产清单检查
249+
理论上,all中的资产和os中的总数保持一致,故可以在`.git/hooks`下创建如下内容的脚本`pre-commit`,以便在commit过程的时候检查资产完整性
250+
```
251+
#!/bin/bash
252+
workspace="/data/workspace/gitlab/ansible"
253+
254+
function ResultOutput() {
255+
if [ ! -z "$3" ];then
256+
echo -e "\033[1;31m $1中存在$2中没有的资产名:$3 \033[0m"
257+
else
258+
echo -e "\033[1;32m $1中的资产在$2中都包含 \033[0m"
259+
fi
260+
}
261+
262+
263+
egrep -v "\[all\]" ${workspace}/inventory/all | awk '{print $1}' | grep -v '^$' | uniq > /tmp/all
264+
egrep -v "\[os|#|^$" ${workspace}/inventory/os | grep -v '^os' | uniq > /tmp/os
265+
266+
os=$(grep -v -f /tmp/all /tmp/os | tr '\n' ',')
267+
ResultOutput "os" "all" "${os}"
268+
os=$(grep -v -f /tmp/os /tmp/all | tr '\n' ',')
269+
ResultOutput "all" "os" "${os}"
270+
271+
# 删除临时文件
272+
find /tmp/all -delete
273+
find /tmp/os -delete
274+
```
275+
276+
脚本创建完成之后,执行
277+
```
278+
chmod +x .git/hooks/pre-commit
279+
```
280+
281+
248282
## Star History
249283

250284
[![Star History Chart](https://api.star-history.com/svg?repos=leif160519/ansible-linux&type=Date)](https://star-history.com/#leif160519/ansible-linux&Date)

0 commit comments

Comments
 (0)