forked from Vonng/pigsty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.yml
executable file
·84 lines (75 loc) · 3.14 KB
/
cache.yml
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File : cache.yml
# Desc : make offline package cache from target nodes
# Ctime : 2024-08-22
# Mtime : 2024-08-22
# Path : cache.yml
# Author : Ruohang Feng ([email protected])
# License : AGPLv3
#==============================================================#
# the default dir for collecting offline package is dist/${version}
- name: CREATE LOCAL DIR
become: no
hosts: localhost
gather_facts: no
tags: cache_dir
tasks:
- name: create local directory
file: path={{ cache_pkg_dir|default('dist/${version}') | replace('${version}', version|default('v3.0.2')) }} state=directory
# gather offline packages from target nodes (the infra node with repo enabled)
- name: MAKE OFFLINE PACKAGE
hosts: all
become: yes
gather_facts: no
vars:
#version: v3.0.2
#cache_pkg_dir: 'dist/${version}' # where to store the cached package? dist/${version} by default
#cache_pkg_name: 'pigsty-pkg-${version}.${os}.${arch}.tgz' # cache offline package filename pattern
#cache_repo: pigsty # target repo(s) to be cached, use `,` to separate multiple repos
#cache_gf_plugin: false # cache grafana plugins, overwriting existing tarball?
roles:
- { role: node_id , tags: id } # get node identity (always)
- { role: cache , tags: cache } # make offline package
# the default dir for collecting offline package is dist/${version}
- name: CREATE LOCAL DIR
become: no
hosts: localhost
gather_facts: no
tags: cache_info
tasks:
- name: calculate cache tarball md5 checksum
shell: |
cd {{ cache_pkg_dir|default('dist/${version}') | replace('${version}', version|default('v3.0.2')) }}
md5sum *.tgz > checksums
cat checksums
ls -lh *.tgz
register: cache_md5
- name: show cache tarball md5 checksum
debug:
msg: "{{ cache_md5.stdout_lines }}"
#---------------------------------------------------------------
# Usage
#---------------------------------------------------------------
# 1. make sure your nodes are already installed with pigsty!
# 2. make sure target nodes are the infra nodes with repo enabled!
#
# cache.yml -l infra # make offline package from the infra group
# cache.yml -l 10.10.10.10 # make offline package from the ad hoc node
#
# The tarball will be generated @ /tmp/pkg.tgz, and copy to dist/${version}
#---------------------------------------------------------------
# Tasks
#---------------------------------------------------------------
# cache_dir : create local dist dir for cache tarball
# id : calculate node identity
# cache_id : calculate cache tarball name
# cache_check : check repo directories exists
# cache_plugin : cache grafana plugins (optional)
# cache_create : adjust and recreate local yum/apt repo
# cache_tgz : make cache tarball from local repos
# cache_fetch : fetch cache tarball from target nodes
# cache_info : generate cache md5sum and print size
#---------------------------------------------------------------
...