Remove reposync roles and profiles #586

Merged
benvin merged 2 commits from benvin/remove-reposync into develop 2026-11-25 22:36:25 +11:00
13 changed files with 0 additions and 780 deletions
-41
View File
@@ -1,41 +0,0 @@
---
hiera_include:
- profiles::reposync::webserver
profiles::ssh::sign::principals:
- packagerepo.service.consul
- packagerepo.query.consul
- "packagerepo.service.%{facts.country}-%{facts.region}.consul"
# additional altnames
profiles::pki::vault::alt_names:
- packagerepo.main.unkin.net
- packagerepo.service.consul
- packagerepo.query.consul
- "packagerepo.service.%{facts.country}-%{facts.region}.consul"
# configure consul service
consul::services:
packagerepo:
service_name: 'packagerepo'
tags:
- 'packagerepo'
address: "%{facts.networking.ip}"
port: 443
checks:
- id: 'packagerepo_http_check'
name: 'packagerepo HTTP Check'
http: "https://%{facts.networking.fqdn}"
method: 'GET'
tls_skip_verify: true
interval: '10s'
timeout: '1s'
profiles::consul::client::node_rules:
- resource: service
segment: packagerepo
disposition: write
profiles::reposync::webserver::nginx_listen_mode: both
profiles::reposync::webserver::nginx_cert_type: vault
profiles::reposync::webserver::www_root: /shared/apps/packagerepo/snap
profiles::reposync::webserver::cache_root: /data/repos/cache
@@ -1,89 +0,0 @@
---
profiles::packages::include:
createrepo: {}
profiles::reposync::repos_list:
docker_stable_el8:
repository: 'stable'
description: 'Docker CE Stable EL8'
osname: 'docker'
release: 'el8'
baseurl: 'https://download.docker.com/linux/centos/8/x86_64/stable/'
gpgkey: 'https://download.docker.com/linux/centos/gpg'
docker_stable_el9:
repository: 'stable'
description: 'Docker CE Stable EL9'
osname: 'docker'
release: 'el9'
baseurl: 'https://download.docker.com/linux/centos/9/x86_64/stable/'
gpgkey: 'https://download.docker.com/linux/centos/gpg'
k8s_1.32:
repository: '1.32'
description: 'Kubernetes 1.32'
osname: 'k8s'
release: '1.32'
baseurl: 'https://pkgs.k8s.io/core:/stable:/v1.32/rpm/'
gpgkey: 'https://pkgs.k8s.io/core:/stable:/v1.32/rpm/repodata/repomd.xml.key'
k8s_1.33:
repository: '1.33'
description: 'Kubernetes 1.33'
osname: 'k8s'
release: '1.33'
baseurl: 'https://pkgs.k8s.io/core:/stable:/v1.33/rpm/'
gpgkey: 'https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key'
puppet7_el8:
repository: '8'
description: 'Puppet 7 EL8'
osname: 'puppet7'
release: 'el'
baseurl: 'https://yum.puppet.com/puppet7/el/8/x86_64/'
gpgkey: 'https://yum.puppet.com/RPM-GPG-KEY-puppet-20250406'
puppet7_el9:
repository: '9'
description: 'Puppet 7 EL9'
osname: 'puppet7'
release: 'el'
baseurl: 'https://yum.puppet.com/puppet7/el/9/x86_64/'
gpgkey: 'https://yum.puppet.com/RPM-GPG-KEY-puppet-20250406'
puppet8_el8:
repository: '8'
description: 'Puppet 8 EL8'
osname: 'puppet8'
release: 'el'
baseurl: 'https://yum.puppet.com/puppet8/el/8/x86_64/'
gpgkey: 'https://yum.puppet.com/RPM-GPG-KEY-puppet-20250406'
puppet8_el9:
repository: '9'
description: 'Puppet 8 EL9'
osname: 'puppet8'
release: 'el'
baseurl: 'https://yum.puppet.com/puppet8/el/9/x86_64/'
gpgkey: 'https://yum.puppet.com/RPM-GPG-KEY-puppet-20250406'
zfs_dkms_rhel8:
repository: 'dkms'
description: 'ZFS DKMS RHEL 8'
osname: 'zfs'
release: 'rhel8'
baseurl: 'http://download.zfsonlinux.org/epel/8/x86_64/'
gpgkey: 'https://packagerepo.service.consul/zfs/gpg/RPM-GPG-KEY-openzfs-2013'
zfs_kmod_rhel8:
repository: 'kmod'
description: 'ZFS KMOD RHEL 8'
osname: 'zfs'
release: 'rhel8'
baseurl: 'http://download.zfsonlinux.org/epel/8/kmod/x86_64/'
gpgkey: 'https://packagerepo.service.consul/zfs/gpg/RPM-GPG-KEY-openzfs-2013'
zfs_dkms_rhel9:
repository: 'dkms'
description: 'ZFS DKMS RHEL 9'
osname: 'zfs'
release: 'rhel9'
baseurl: 'http://download.zfsonlinux.org/epel/9/x86_64/'
gpgkey: 'https://packagerepo.service.consul/zfs/gpg/RPM-GPG-KEY-openzfs-2022'
zfs_kmod_rhel9:
repository: 'kmod'
description: 'ZFS KMOD RHEL 9'
osname: 'zfs'
release: 'rhel9'
baseurl: 'http://download.zfsonlinux.org/epel/9/kmod/x86_64/'
gpgkey: 'https://packagerepo.service.consul/zfs/gpg/RPM-GPG-KEY-openzfs-2022'
Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

@@ -1,105 +0,0 @@
# setup the autopromoter
class profiles::reposync::autopromoter {
# Ensure the autopromoter script is present and executable
file { '/usr/local/bin/autopromoter':
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0755',
content => template('profiles/reposync/autopromoter.erb'),
}
# daily autopromote service/timer
$_daily_timer = @(EOT)
[Unit]
Description=autopromoter daily timer
[Timer]
OnCalendar=*-*-* 05:00:00
RandomizedDelaySec=1s
[Install]
WantedBy=timers.target
EOT
$_daily_service = @(EOT)
[Unit]
Description=autopromoter daily service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/autopromoter daily
User=root
Group=root
PermissionsStartOnly=false
PrivateTmp=no
EOT
systemd::timer { 'autopromoter-daily.timer':
timer_content => $_daily_timer,
service_content => $_daily_service,
active => true,
enable => true,
require => File['/usr/local/bin/autopromoter'],
}
# weekly autopromote service/timer
$_weekly_timer = @(EOT)
[Unit]
Description=autopromoter weekly timer
[Timer]
OnCalendar=Sun *-*-* 05:05:00
RandomizedDelaySec=1s
[Install]
WantedBy=timers.target
EOT
$_weekly_service = @(EOT)
[Unit]
Description=autopromoter weekly service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/autopromoter weekly
User=root
Group=root
PermissionsStartOnly=false
PrivateTmp=no
EOT
systemd::timer { 'autopromoter-weekly.timer':
timer_content => $_weekly_timer,
service_content => $_weekly_service,
active => true,
enable => true,
require => File['/usr/local/bin/autopromoter'],
}
# monthly autopromote service/timer
$_monthly_timer = @(EOT)
[Unit]
Description=autopromoter monthly timer
[Timer]
OnCalendar=*-*-01 05:10:00
RandomizedDelaySec=1s
[Install]
WantedBy=timers.target
EOT
$_monthly_service = @(EOT)
[Unit]
Description=autopromoter monthly service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/autopromoter monthly
User=root
Group=root
PermissionsStartOnly=false
PrivateTmp=no
EOT
systemd::timer { 'autopromoter-monthly.timer':
timer_content => $_monthly_timer,
service_content => $_monthly_service,
active => true,
enable => true,
require => File['/usr/local/bin/autopromoter'],
}
}
@@ -1,46 +0,0 @@
# setup the autosyncer
class profiles::reposync::autosyncer (
Stdlib::Absolutepath $basepath = '/shared/apps/packagerepo',
) {
# Ensure the autosyncer script is present and executable
file { '/usr/local/bin/autosyncer':
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0755',
content => template('profiles/reposync/autosyncer.erb'),
require => Package['createrepo'],
}
# daily autosyncr service/timer
$_timer = @(EOT)
[Unit]
Description=autosyncer timer
[Timer]
OnCalendar=*-*-* 03:00:00
RandomizedDelaySec=1s
[Install]
WantedBy=timers.target
EOT
$_service = @(EOT)
[Unit]
Description=autosyncer service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/autosyncer
User=root
Group=root
PermissionsStartOnly=false
PrivateTmp=no
EOT
systemd::timer { 'autosyncer.timer':
timer_content => $_timer,
service_content => $_service,
active => true,
enable => true,
require => File['/usr/local/bin/autosyncer'],
}
}
-52
View File
@@ -1,52 +0,0 @@
# define to generate repositories in yum
define profiles::reposync::repos (
String $repository,
String $description,
String $osname,
String $release,
Stdlib::Filesource $gpgkey,
String $arch = 'x86_64',
String $repo_owner = 'root',
String $repo_group = 'root',
Stdlib::Absolutepath $basepath = '/shared/apps/packagerepo',
Optional[Stdlib::HTTPUrl] $baseurl = undef,
Optional[Stdlib::HTTPUrl] $mirrorlist = undef,
){
if ($mirrorlist == undef and $baseurl == undef) or ($mirrorlist != undef and $baseurl != undef) {
fail('profiles::reposync::repos must have either mirrorlist or baseurl set, but not both')
}
$repos_name = downcase("${osname}-${release}-${repository}-${arch}")
$conf_file = "/etc/reposync/conf.d/${repos_name}.conf"
# Create the repository configuration
yumrepo { $repos_name:
ensure => 'present',
descr => $description,
baseurl => $baseurl,
mirrorlist => $mirrorlist,
gpgkey => $gpgkey,
target => '/etc/yum.repos.d/reposync.repo',
enabled => 0,
gpgcheck => 1,
}
# Ensure the repo dest path exists
file { "${basepath}/live/${repos_name}" :
ensure => 'directory',
owner => $repo_owner,
group => $repo_group,
mode => '0755',
}
# Create the repo configuration file
file { $conf_file:
ensure => file,
owner => $repo_owner,
group => $repo_group,
mode => '0644',
content => template('profiles/reposync/repo_conf.erb'),
require => File['/etc/reposync/conf.d'],
}
}
@@ -1,31 +0,0 @@
# setup a reposync syncer
class profiles::reposync::syncer {
include profiles::reposync::autosyncer
include profiles::reposync::autopromoter
# Ensure the reposync config path exists
file { '/etc/reposync':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
file { '/etc/reposync/conf.d':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
purge => true,
recurse => true,
force => true,
}
# get a list of repos as a hash, and iterate through them
$repos = lookup('profiles::reposync::repos_list', {})
$repos.each | String $name, Hash $repo_hash | {
profiles::reposync::repos { $name:
* => $repo_hash,
}
}
}
@@ -1,181 +0,0 @@
# setup a reposync webserver
class profiles::reposync::webserver (
String $www_root = '/data/repos/snap',
String $cache_root = '/data/repos/cache',
String $nginx_vhost = 'packagerepo.service.consul',
Stdlib::Port $nginx_port = 80,
Stdlib::Port $nginx_ssl_port = 443,
Boolean $favicon = true,
Enum['http','https','both'] $nginx_listen_mode = 'http',
Enum['puppet', 'vault'] $nginx_cert_type = 'vault'
) {
# ensure all the required directories exist
mkdir::p { $www_root: }
mkdir::p { $cache_root: }
# select the certificates to use based on cert type
case $nginx_cert_type {
'puppet': {
$selected_ssl_cert = "/etc/pki/tls/puppet/${facts['networking']['fqdn']}.crt"
$selected_ssl_key = "/etc/pki/tls/puppet/${facts['networking']['fqdn']}.key"
}
'vault': {
$selected_ssl_cert = '/etc/pki/tls/vault/certificate.crt'
$selected_ssl_key = '/etc/pki/tls/vault/private.key'
}
default: {
# enum param prevents this ever being reached
}
}
# set variables based on the listen_mode
case $nginx_listen_mode {
'http': {
$enable_ssl = false
$ssl_cert = undef
$ssl_key = undef
$listen_port = $nginx_port
$listen_ssl_port = undef
$extras_hash = {}
}
'https': {
$enable_ssl = true
$ssl_cert = $selected_ssl_cert
$ssl_key = $selected_ssl_key
$listen_port = $nginx_ssl_port
$listen_ssl_port = $nginx_ssl_port
$extras_hash = {
'subscribe' => [File[$ssl_cert], File[$ssl_key]],
}
}
'both': {
$enable_ssl = true
$ssl_cert = $selected_ssl_cert
$ssl_key = $selected_ssl_key
$listen_port = $nginx_port
$listen_ssl_port = $nginx_ssl_port
$extras_hash = {
'subscribe' => [File[$ssl_cert], File[$ssl_key]],
}
}
default: {
# enum param prevents this ever being reached
}
}
# define the default parameters for the nginx server
$defaults = {
'listen_port' => $listen_port,
'server_name' => [$nginx_vhost],
'use_default_location' => true,
'access_log' => [
"/var/log/nginx/${nginx_vhost}_access.log",
'syslog:server=unix:/dev/log,tag=nginx_access,nohostname journald',
],
'error_log' => [
"/var/log/nginx/${nginx_vhost}_error.log",
'syslog:server=unix:/dev/log,tag=nginx,nohostname',
],
'www_root' => $www_root,
'autoindex' => 'on',
'ssl' => $enable_ssl,
'ssl_cert' => $ssl_cert,
'ssl_key' => $ssl_key,
'ssl_port' => $listen_ssl_port,
}
# merge the hashes conditionally
$nginx_parameters = merge($defaults, $extras_hash)
# manage the nginx class
class { 'nginx':
proxy_cache_path => {
"${cache_root}/debian" => 'debian:128m',
},
proxy_cache_levels => '1:2',
proxy_cache_keys_zone => 'debian:128m',
proxy_cache_max_size => '30000m',
proxy_cache_inactive => '60d',
proxy_temp_path => "${cache_root}/tmp",
manage_repo => false,
require => [
Mkdir::P[$cache_root],
Mkdir::P[$www_root]
]
}
# create the nginx vhost with the merged parameters
create_resources('nginx::resource::server', { $nginx_vhost => $nginx_parameters })
# cache debian packages from upstream
nginx::resource::location { "${nginx_vhost}-debian":
ensure => present,
ssl => true,
ssl_only => false,
location => '/debian',
server => $nginx_vhost,
proxy => 'http://mirror.gsl.icu/debian',
}
nginx::resource::location { "${nginx_vhost}-debian_pool":
ensure => present,
ssl => true,
ssl_only => false,
location => '/debian/pool',
server => $nginx_vhost,
proxy => 'http://mirror.gsl.icu/debian/pool',
proxy_cache => 'debian',
proxy_cache_valid => [
'200 302 1440h',
'404 1m'
],
}
if $favicon {
file { "${www_root}/favicon.ico":
ensure => 'file',
owner => 'root',
group => 'root',
mode => '0644',
source => 'puppet:///modules/profiles/reposync/favicon.ico',
}
}
if $::facts['os']['selinux']['config_mode'] == 'enforcing' {
# set httpd_sys_content_t to all files under the www_root
selinux::fcontext { $www_root:
ensure => 'present',
seltype => 'httpd_sys_content_t',
pathspec => "${www_root}(/.*)?",
}
# set httpd_sys_rw_content_t to all files under the cache_root
selinux::fcontext { $cache_root:
ensure => 'present',
seltype => 'httpd_sys_rw_content_t',
pathspec => "${cache_root}(/.*)?",
}
# make sure we can connect to port 80
selboolean { 'httpd_can_network_connect':
persistent => true,
value => 'on',
}
exec { "restorecon_${www_root}":
path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'],
command => "restorecon -Rv ${www_root}",
refreshonly => true,
subscribe => Selinux::Fcontext[$www_root],
}
exec { "restorecon_${cache_root}":
path => ['/bin', '/usr/bin', '/sbin', '/usr/sbin'],
command => "restorecon -Rv ${cache_root}",
refreshonly => true,
subscribe => Selinux::Fcontext[$cache_root],
}
}
}
@@ -1,107 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
: "${DRY_RUN:=}" # set DRY_RUN=1 to preview deletions
log() { printf '[%(%F %T)T] %s\n' -1 "$*" >&2; }
# Function to create symlink for snapshots
create_symlink() {
local osname="$1" # e.g. almalinux
local release="$2" # e.g. 9.6
local repository="$3" # e.g. appstream
local basepath="$4" # e.g. /shared/apps/packagerepo
local label="$5" # monthly|weekly|daily
local date_value="$6" # YYYYMMDD for the snapshot to promote
local snap_path="${basepath}/snap/${osname}/${release}/${repository}-${date_value}"
local symlink_target="${basepath}/snap/${osname}/${release}/${repository}-${label}"
if [[ -d "$snap_path" ]]; then
ln -sfn "$snap_path" "$symlink_target"
log "Symlink set: ${symlink_target} -> ${snap_path}"
return 0
else
log "Snapshot path does not exist: $snap_path"
return 1
fi
}
# Cleanup snapshot directories older than a cutoff date (YYYYMMDD)
cleanup_older_than_monthly() {
local osname="$1"
local release="$2"
local repository="$3"
local basepath="$4"
local cutoff_date="$5" # newly promoted monthly date, YYYYMMDD
local root="${basepath}/snap/${osname}/${release}"
local pattern="${repository}-"[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
shopt -s nullglob
for dir in "${root}"/${pattern}; do
# Skip symlinks and non-directories
[[ -L "$dir" ]] && continue
[[ -d "$dir" ]] || continue
# Extract the date suffix
local name base datepart
name="$(basename -- "$dir")"
base="${name%-????????}" # remove last 8 chars
datepart="${name#${base}-}" # after "<repo>-"
# Only act on valid YYYYMMDD dates
if [[ "$datepart" =~ ^[0-9]{8}$ ]]; then
if [[ "$datepart" -lt "$cutoff_date" ]]; then
if [[ -n "${DRY_RUN}" ]]; then
log "[DRY_RUN] Would remove: $dir"
else
log "Removing: $dir"
rm -rf --one-file-system -- "$dir"
fi
fi
fi
done
shopt -u nullglob
}
# Determine which snapshot to promote based on the passed argument
case "${1:-}" in
monthly)
promote_date=$(date --date="$(date +%Y%m01) -1 month" +%Y%m%d)
;;
weekly)
promote_date=$(date --date="last Sunday" +%Y%m%d)
;;
daily)
promote_date=$(date --date="yesterday" +%Y%m%d)
;;
*)
echo "Usage: $0 {monthly|weekly|daily}"
exit 1
;;
esac
label="$1"
# Process each repo conf
for conf in /etc/reposync/conf.d/*.conf; do
# shellcheck disable=SC1090
source "$conf"
# Expecting these vars in the conf: OSNAME, RELEASE, REPOSITORY, BASEPATH
: "${OSNAME:?missing OSNAME in $conf}"
: "${RELEASE:?missing RELEASE in $conf}"
: "${REPOSITORY:?missing REPOSITORY in $conf}"
: "${BASEPATH:?missing BASEPATH in $conf}"
# 1) Promote the symlink for this label
if create_symlink "$OSNAME" "$RELEASE" "$REPOSITORY" "$BASEPATH" "$label" "$promote_date"; then
# 2) If monthly, clean up older snapshot dirs for this repo
if [[ "$label" == "monthly" ]]; then
cleanup_older_than_monthly "$OSNAME" "$RELEASE" "$REPOSITORY" "$BASEPATH" "$promote_date"
fi
else
log "Skipping cleanup for ${OSNAME}/${RELEASE}/${REPOSITORY} due to missing ${REPOSITORY}-${promote_date}"
fi
done
@@ -1,97 +0,0 @@
#!/usr/bin/bash
# Function to perform reposync
perform_reposync() {
local reponame="$1"
local basepath="$2"
/usr/bin/dnf reposync \
--gpgcheck \
--delete \
--downloadcomps \
--download-metadata \
--remote-time \
--disablerepo="*" \
--enablerepo="${reponame}" \
--download-path="${basepath}/live"
}
# Function to download GPG keys
download_gpg_key() {
local gpgkeyurl="$1"
local reponame="$2"
local basepath="$3"
# Extract filename from URL
local filename=$(basename "$gpgkeyurl")
# Download GPG key to the specified path with the filename from the URL
curl -s --create-dirs -o "${basepath}/live/${reponame}/${filename}" "$gpgkeyurl" || {
echo "Failed to download GPG key from $gpgkeyurl"
}
# import the gpg key
rpm --import "${basepath}/live/${reponame}/${filename}" || echo "Failed to import gpg key ${basepath}/live/${reponame}/${filename}"
}
# Function to perform rsync with hard links
perform_rsync() {
local source_path="$1"
local dest_path="$2"
# Create the destination directory if it doesn't exist
mkdir -p "$dest_path"
# Use rsync to create hard links to the files in the destination directory
rsync -a --link-dest="$source_path" "$source_path"/* "$dest_path"
}
create_repo_metadata() {
local repo_path="${1}"
if [[ -d "$repo_path" ]]; then
echo "Running createrepo on ${repo_path}..."
createrepo --update "${repo_path}"
if [[ $? -eq 0 ]]; then
echo "Successfully created repository metadata for ${repo_path}"
else
echo "Failed to create repository metadata for ${repo_path}" >&2
return 1
fi
else
echo "The specified repository path does not exist: ${repo_path}" >&2
return 1
fi
}
# Current date in the required format
DATE=$(date +%Y%m%d)
# iterate over each configuration file
for conf in /etc/reposync/conf.d/*.conf; do
# source the configuration to get the variables
source "$conf"
# Call the function to download the GPG key
download_gpg_key "$GPGKEYURL" "$REPONAME" "$BASEPATH"
# Call the reposync function
perform_reposync "$REPONAME" "$BASEPATH"
# Path for rsync source
live_path="${BASEPATH}/live/${REPONAME}"
# Path for rsync destination
snap_path="${BASEPATH}/snap/${OSNAME}/${RELEASE}/${REPOSITORY}-${DATE}/${ARCH}/os"
# Call the rsync function
perform_rsync "$live_path" "$snap_path"
# After syncing each repo, fix the repository metadata
create_repo_metadata "${snap_path}"
# Update selinux
restorecon -R ${snap_path}
done
@@ -1,8 +0,0 @@
# <%= @osname %>-<%= @release %>-<%= @repository %> repository configuration
REPOSITORY="<%= @repository %>"
REPONAME="<%= @repos_name %>"
OSNAME="<%= @osname %>"
RELEASE="<%= @release %>"
ARCH="<%= @arch %>"
BASEPATH="<%= @basepath %>"
GPGKEYURL="<%= @gpgkey %>"
@@ -1,11 +0,0 @@
# a role to deploy the webserver for packagerepo
class roles::infra::reposync::repo {
if $facts['firstrun'] {
include profiles::defaults
include profiles::firstrun::init
}else{
include profiles::defaults
include profiles::base
include profiles::base::datavol
}
}
@@ -1,12 +0,0 @@
# a role to deploy the syncer/promoter for packagerepo
class roles::infra::reposync::syncer {
if $facts['firstrun'] {
include profiles::defaults
include profiles::firstrun::init
}else{
include profiles::defaults
include profiles::base
include profiles::base::datavol
include profiles::reposync::syncer
}
}