-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathcache.yml
More file actions
executable file
·137 lines (126 loc) · 5.18 KB
/
cache.yml
File metadata and controls
executable file
·137 lines (126 loc) · 5.18 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File : cache.yml
# Desc : Create offline package cache from infra nodes
# Ctime : 2024-08-22
# Mtime : 2024-12-31
# Path : cache.yml
# Docs : https://pigsty.io/docs/setup/offline
# License : Apache-2.0 @ https://pigsty.io/docs/about/license/
# Copyright : 2018-2026 Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
# This playbook creates an offline package tarball from an
# existing local repository on infra nodes. The tarball can be
# used for air-gapped/offline installations.
#
# Prerequisites:
# - Pigsty must be installed on the target node with repo_enabled
# - Local repo must exist at /www/pigsty (run infra.yml first)
#
# Output:
# dist/${version}/pigsty-pkg-${version}.${os}.${arch}.tgz
#
# Example:
# ./cache.yml -l infra # from infra group
# ./cache.yml -l 10.10.10.10 # from specific node
#==============================================================#
#--------------------------------------------------------------#
# PLAY 1: Create local directory for cache tarball [cache_dir]
#--------------------------------------------------------------#
- name: CREATE LOCAL DIST DIR
hosts: localhost
become: false
gather_facts: no
tags: cache_dir
tasks:
- name: create local dist directory
file:
path: "{{ cache_pkg_dir | default('dist/${version}') | replace('${version}', version | default('v4.2.2')) }}"
state: directory
mode: '0755'
#--------------------------------------------------------------#
# PLAY 2: Make offline package from target node [id,cache]
#--------------------------------------------------------------#
# This play runs on the target infra node to:
# 1. Detect node identity (OS, version, architecture)
# 2. Clean dirty packages and recreate repo metadata
# 3. Create compressed tarball at /tmp/pkg.tgz
# 4. Fetch tarball back to control node
#--------------------------------------------------------------#
- name: MAKE OFFLINE PACKAGE
hosts: all
become: true
gather_facts: no
vars:
#version: v4.2.2
#cache_repo: pigsty # target repo(s) to be cached, use `,` to separate multiple repos
#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
roles:
- { role: node_id, tags: id } # detect node identity
- { role: cache, tags: cache } # create and fetch cache tarball
#--------------------------------------------------------------#
# PLAY 3: Calculate checksums and display info [cache_info]
#--------------------------------------------------------------#
- name: SHOW CACHE TARBALL INFO
hosts: localhost
become: false
gather_facts: no
tags: cache_info
tasks:
- name: ensure cache directory exists
file:
path: "{{ cache_pkg_dir | default('dist/${version}') | replace('${version}', version | default('v4.2.2')) }}"
state: directory
mode: '0755'
- name: calculate cache tarball checksums
shell: |
cd "{{ cache_pkg_dir|default('dist/${version}') | replace('${version}', version|default('v4.2.2')) }}"
md5sum *.tgz > checksums
cat checksums
ls -lh *.tgz
register: cache_result
- name: display cache information
debug:
msg: "{{ cache_result.stdout_lines }}"
#==============================================================#
# Usage Examples
#==============================================================#
#
# ./cache.yml -l infra # create cache from infra group
# ./cache.yml -l 10.10.10.10 # create cache from specific node
# ./cache.yml -l infra -t cache_dir # create local dist dir only
#
# # Override version
# ./cache.yml -l infra -e version=v4.2.2
#
# # Cache multiple repos
# ./cache.yml -l infra -e cache_repo=pigsty,minio
#
#==============================================================#
# Tag Reference
#==============================================================#
#
# cache_dir : create local dist directory (localhost)
# id : detect node identity (OS, version, arch)
# cache : full cache role execution
# cache_id : calculate cache tarball filename
# cache_check : verify repo directories exist and not empty
# cache_create : clean dirty packages, recreate repo metadata
# cache_tgz : create /tmp/pkg.tgz tarball on target
# cache_fetch : fetch tarball from target to control node
# cache_info : calculate md5sum and display file sizes
#
#==============================================================#
# Workflow
#==============================================================#
#
# 1. Ensure Pigsty is installed: ./deploy.yml
# 2. Create offline package: ./cache.yml -l infra
# 3. Transfer to air-gapped env: scp dist/v4.2.2/*.tgz target:/tmp/
# 4. Bootstrap with package: ./bootstrap -p /tmp/pigsty-pkg-*.tgz
# 5. Configure and install: ./configure && ./deploy.yml
#
#==============================================================#
...