Ctrl K
ComunidadGuías…

cache.yml

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
#!/usr/bin/env ansible-playbook
---
#==============================================================#
# File      :   cache.yml
# Desc      :   Create offline package cache from infra nodes
# Ctime     :   2024-08-22
# Mtime     :   2026-08-14
# 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: all
  become: false
  gather_facts: no
  tags: cache_dir
  tasks:
    - name: create local dist directory
      run_once: true
      delegate_to: localhost
      file:
        path: "{{ cache_pkg_dir | default('dist/${version}') | replace('${version}', version | default('v4.6.0')) }}"
        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. Copy the local Pigsty source release artifact when present
#   3. Clean dirty packages and recreate repo metadata
#   4. Create compressed tarball at cache_tmp_dir/pkg.tgz
#   5. Fetch tarball back to control node
#--------------------------------------------------------------#
- name: MAKE OFFLINE PACKAGE
  hosts: all
  become: true
  gather_facts: no
  vars:
    #version: v4.6.0
    #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: all
  become: false
  gather_facts: no
  tags: cache_info
  tasks:

    - name: ensure cache directory exists
      run_once: true
      delegate_to: localhost
      file:
        path: "{{ cache_pkg_dir | default('dist/${version}') | replace('${version}', version | default('v4.6.0')) }}"
        state: directory
        mode: '0755'

    - name: calculate cache tarball checksums
      run_once: true
      delegate_to: localhost
      shell: |
        cd "{{ cache_pkg_dir|default('dist/${version}') | replace('${version}', version|default('v4.6.0')) }}"
        md5sum *.tgz > checksums
        cat checksums
        ls -lh *.tgz
      register: cache_result

    - name: display cache information
      run_once: true
      delegate_to: localhost
      debug:
        msg: "{{ cache_result.stdout_lines | default([]) }}"


#==============================================================#
# 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.6.0
#
#   # Cache multiple repos
#   ./cache.yml -l infra -e cache_repo=pigsty,minio
#
#   # Optional source: pre-stage dist/${version}/pigsty-${version}.tgz before running
#
#==============================================================#
# 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_src    : copy pre-staged Pigsty source release artifact when present
#   cache_create : clean dirty packages, recreate repo metadata
#   cache_tgz    : create cache_tmp_dir/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.6.0/pigsty-pkg-v4.6.0.el9.x86_64.tgz target:/var/tmp/pkg.tgz
#   4. Bootstrap with package:      ./bootstrap
#   5. Configure and install:       ./configure && ./deploy.yml
#
#==============================================================#
...