Red Hat Enterprise Linux

How to clean old content view in satellite:

Introduction:

A content view in Red Hat Satellite is a collection of repositories, filters, and associated metadata that you can use to control and manage the software content in your environment. It provides a way to organize, curate, and control what content (e.g., packages, patches) is pushed to different environments (e.g., development, quality assurance, production).

When you need to add packages, it is necessary to publish a new version and promote it to prod, dev, stage of library (default).
After some time, we will have lots of version.
According to our experience and RedHat documentation, lot of versions can cause some issues.
Our recommendation is to delete old versions.

Procedure:
You can delete old content view version using two ways.
1. Delete it manually
2. Delete it via hammer script.

Hammer is a command-line interface (CLI) tool for Red Hat Satellite that allows you to interact with and manage Satellite tasks programmatically. It’s useful for automating tasks such as provisioning hosts, managing content views, and performing other administrative functions without using the web UI.

Manually:

  1. You should select organization and location.

2. Go to content -> content view -> select my_content_view

3. You can see that we already have two published versions.

4. You can select a version -> click on the 3 dots -> delete version.

Automatically:

  1. SSH to satellite server
  2. Create /usr/local/etc/clean-content-view-old-version.sh file
  3. Vi to this file
  4. Create the script.
#!/bin/bash 
for CV in 'hammer content-view list | awk '{print $1}' | grep [0-9]'
do 
             hammer content-view purge --id $CV 
done

5. Pay attention to add execute permission to the file:

# chmod +x /usr/local/etc/clean-content-view-old-version.sh

awk ‘/[0-9]+/ {print $1}’: This extracts the first field (assumed to be the ID) from the output where the first column is a number (Mcontent view ID).

Purge Command: For each content view ID ($CV), it runs the hammer content-view purge command.

You can also create a cronjob for this script:
This job running every 2 weeks on Sunday 9:00 AM

# crontab -e
# 0 9 * * 0 [ $(($sate +%s) / 604800 % 2)) -eq 0 ] && /usr/local/etc/clean-content-view-old-version.sh

Summary:
In this post we have seen how to clean old content view in
satellite. We understand the concepts of content-view, hammer cli, and we saw
two ways to delete the old content view versions.
Manually and automatically. Moreover, we saw how we can create a cronjob for
this script.

Red Hat
Red Hat

חברת אוקטופוס היא שותף בכיר של Red Hat בישראל ומציעים רישוי לכלל מוצרי Red Hat במחירים תחרותיים וכן את שירותי ייעוץ המומחים שלנו מאחוריהם אלפי שעות בפרויקטים המורכבים ביותר במשק.

צור קשר