Skip to content

Instantly share code, notes, and snippets.

@JRNC
Last active January 19, 2023 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRNC/62ebe4b9045ed06420f26be0d878e7e0 to your computer and use it in GitHub Desktop.
Save JRNC/62ebe4b9045ed06420f26be0d878e7e0 to your computer and use it in GitHub Desktop.
HOSTS=$(hammer host list --fields Id | grep -v ID | grep -v -- --)
for i in ${HOSTS}
do
subscriptions=$(hammer host subscription product-content --host-id $i --fields Name | grep -v "Red Hat" | grep -v "NAME" | grep -v -- ----------------------------------------------------------------------------)
echo "$subscriptions" > "$i"
hash=$(sha256sum $i | cut -d " " -f 1)
rm $i
echo $i >> $hash
echo $hash >> array
done
awk -i inplace '!seen[$0]++' array
while read hash
do
hammer host-collection create --name $hash --organization "CHANGEME"
ids=$(paste -d, -s $hash)
hammer host-collection add-host --name $hash --host-ids $ids --organization "CHANGEME"
done <array
@JRNC
Copy link
Author

JRNC commented Jan 19, 2023

This script will identify and group hosts in Satellite that share the same exact set of subscriptions and create a host collection per grouping. This is helpful for teams that are preparing to enable Simple Content Access; however, need to first disable all of the unsubscribed repositories that set themselves to enabled by default. Instead of disabling unsubscribed repositories host by host, this will trim it down, so that you can disable unsubscribed repositories host collection by host collection. It is not perfect, but it decreases the amount of time required to perform this task.

This script should be run within its own dedicated directory (ideally), as it will create many files as part of the work that it is performing.

DISCLAIMER
This script is being made available publicly without support or guarantee of proper functionality. Please modify the script as you see fit for your needs and always test in a NON-production environment and ensure proper functionality for yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment