Hammer command to list hosts with host collections

Latest response

Hello everyone,

I am looking to see if there is a hammer command to be able to list all the content hosts along with which host collection groups they are in. I am using 6.3.3.

I am reviewing the hammer list and cannot find such a command:

hammer host list --organization-id x

Does not show the host collection groups, but just shows the Host Group. Not what I am looking for.

My initial way of doing such was to use a search of:

host_collection != "1st Dev Test" and host_collection != "1st Prd Test" and host_collection != "2nd Dev Test" and host_collection != "2nd Prd Test"

I have tried to replace the "and" with "or" and have the same results.

However, when you combine searches like that you do not get results, which is a bug: https://bugzilla.redhat.com/show_bug.cgi?id=1635331 and according to support there is no ETA to have this resolved.

My use for this is that I am patching content hosts based off of the host collection groups they are in. Adding the patching host collection group to the content host is a manual process so I want to make sure there is some sort of auditing.

Is there another way to display the information that I am looking for?


I came up with this scrip, which is commented for readability:

#set -x
#trap read debug

#check if there is a "-h" or "--help" for help, or no $1
[ "$1" = "--h" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] && echo "This script gets all hosts in a list by host collection:"

#clean working files
/usr/bin/rm hc_*

echo "getting all host collections with hosts and putting them in files"
# get hosts collection ID's
        hammer --csv host-collection list | grep -v "Name,Limit"| cut -d, -f1 | while read hcnum; do
#get host_collection_name
            hcname=`hammer --csv host-collection info --id=$hcnum | tail -1 | cut -d, -f2`
# put hosts from host collections into list
            hammer --csv host-collection hosts --id $hcnum| grep -v ID | cut -d, -f2 | sort >> hc_"$hcname"
        echo "still working"
echo "next step, getting all hosts"
#clean hosts_and_hc file so it is frech

#get list of all hosts and loop through them
hammer --csv host list| grep -v Name | cut -d, -f2 | while read host; do
    ## echo the hostname to the file
    echo $host >> hosts_and_hc
    ## echo the host collections the host is found in to the file
    grep $host hc* >> hosts_and_hc
echo "completed! Check the file hosts_and_hc for a list of all hosts and the host collection the belong to"