How to identify unused Content Views in Satellite6?

Solution Verified - Updated

Environment

Red Hat Satellite 6

Issue

Having many Content Views (CVs) with many versions, promoted to more Lifecycle Envronments (LEs), is there an easy way to identify:

  • what CVs are not associated with any Content Host?
  • what CVs promoted to what LEs are not associated with any Content Host?
  • what CV versions are not promoted to any LE?

Resolution

One option is to use ansible role from This content is not included.This content is not included.https://console.redhat.com/ansible/automation-hub/repo/published/redhat/satellite/content/role/content_view_version_cleanup.

Another option is to use the below rake script find_unused_CVs.rake:

def ids_to_names(idlist, klass)
  idlist.map{|id| klass.find(id).name}
end

Katello::Host::ContentFacet.all().each() do |cf|
  used_CV_LEs.add(cf.content_view_environments.pluck(:id))
end
used_CVs = used_CV_LEs.map{|cvle| Katello::ContentViewEnvironment.find(cvle)[0].content_view_id}.sort.uniq

existing_CVs = Katello::ContentView.pluck(:id)
unused_CVs = existing_CVs - used_CVs
unused_CV_names = ids_to_names(unused_CVs, Katello::ContentView)
puts "Unused CVs: #{unused_CV_names}"

existing_CV_LEs = Katello::ContentViewEnvironment.pluck(:id)
unused_CV_LEs = Set.new(existing_CV_LEs) - used_CV_LEs
unused_CV_LEs_names = unused_CV_LEs.map{|cvle| [Katello::ContentViewEnvironment.find(cvle).content_view_name, Katello::ContentViewEnvironment.find(cvle).environment_name]}
puts "Unused CV+LE promotions: #{unused_CV_LEs_names}"


nonpromoted_CV_versions = Hash.new

for cvid in existing_CVs
  cv = Katello::ContentView.find(cvid)
  unused_versions = []
  cvvs = cv.content_view_versions.map{|ccv| [ccv.major, ccv.minor, ccv.environments.count]}
  cvvs.each { |maj, min, c| unused_versions << "#{maj}.#{min}" if c==0 }
  if unused_versions.size > 0
    nonpromoted_CV_versions[cv.name] = unused_versions
  end
end

puts "CV versions not promoted to any LE: #{nonpromoted_CV_versions}"

Execute it:

cat find_unused_CVs.rake | foreman-rake console > find_unused_CVs.rake.out

Find the relevant output:

# grep -A1 ^puts find_unused_CVs.rake.out | grep -v ^puts
Unused CVs: ["cv_123456_rhel6", "CV_rhel7tools_no_no_2021-01-01", "CV_RHEL7tools_no_include_2021-05-01", "cv_tools_filtered", "cv_sos", "ccv_tools_sos", "CVZOOS_RHEL7_yes_include_2021-11-01", "cv_discussion_6129221", "cv_test3", "Default Organization View", "cv_tools_zoo_depsolving", "cv_tools_zoo_NOdepsolve", "CVZOOS_RHEL7_no_include_2021-11-01", "CVZOOS_RHEL7_yes_no_1980-01-01"]
--
Unused CV+LE promotions: [["CV_rhel8tools_no_no_2021-01-01", "Library"], ["cv_tools_filtered", "Library"], ["cv_sos", "Library"], ["cv_discussion_6129221", "Library"], ["cv_test3", "Library"], ["Default Organization View", "Library"], ["cv_tools_zoo_depsolving", "Library"], ["cv_tools_zoo_NOdepsolve", "Library"], ["cv_123456_rhel6", "Library"], ["CVZOOS_RHEL7_yes_include_2021-11-01", "Library"], ["CVZOOS_RHEL7_no_include_2021-11-01", "Library"], ["CVZOOS_RHEL7_yes_no_1980-01-01", "Library"]]
--
CV versions not promoted to any LE: {"cv_123456_rhel6"=>["1.0", "2.0", "3.0", "4.0", "5.0"], "CV_RHEL7tools_no_include_2021-05-01"=>["1.0"], "cv_tools_filtered"=>["1.0"], "cv_sos"=>["1.0", "1.1", "2.1", "2.2", "2.3", "2.4"], "ccv_tools_sos"=>["1.0", "2.0"], "CVZOOS_RHEL7_yes_include_2021-11-01"=>["1.0", "2.0", "3.0", "4.0"], "cv_discussion_6129221"=>["2.0", "1.0"], "CVZOOS_RHEL7_no_include_2021-11-01"=>["1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0"], "CVZOOS_RHEL7_yes_no_1980-01-01"=>["1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0"]}
#

Use the output with caution, as the script just finds such "unused" CV (versions) and e.g. does not take into account composite CVs.

For more KB articles/solutions related to Red Hat Satellite 6.x Content View Issues, please refer to the Red Hat Satellite Consolidated Troubleshooting Article for Red Hat Satellite 6.x Content View Issues

SBR
Product(s)
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.