List hosts or content-hosts per host-collection
My Satellite clients are grouped into several categories of host-collections. Now I want to select them by host-collection. Best would be a hammer list command with an option "host-collection MYCOLLECTION" but I would already be happy if I could get a list of all hosts with their host-collection.
Apologies if asked at the wrong place and/or stupid question.
Responses
Maybe bookmark the Getting Help section of the Hammer CLI guide.
Hello,
OK, sorry for my misunderstanding.
I just created a host collection Test_HC and added one machine rhel7-3-server-test.
hammer host list --search Test_HC
---|-------------------------|---------------|------------|-|---------
ID | NAME | OPERATING SYS | HOST GROUP | | CONTENT
---|-------------------------|---------------|------------|-|---------
8 | rhel7-3-server-test.sat | RedHat 7.3 | TestHG-1 | | Default
---|-------------------------|---------------|------------|-|---------
I trimmed the output a bit. Hope it displays OK. (2nd try)
Search is one of the most powerful functions. Basically anything that can be searched for in the UI is capable of being passed to hammer.
The search that Stephen provided above is a free-text search and will match (in his example) on any property of the host that contains Test_HC.
For a proper host-collection search (that truly tests membership), you'd want to use
hammer host list --search "host_collection = Test_HC"
NOTE: You can use AND, OR, and NOT to better search. Example (to find systems that are in the Test_HC host collection AND are virtual):
hammer host list --search "host_collection = Test_HC and facts.is_virtual = true"
For getting a list of hosts for each host-collection, I guess you first have get a list of all host-collections, then use that to get the hosts for each.
I use this script:
#!/bin/bash
# 2017-04-27 tetra
# List all host collections, and the hosts in them
ORG="<add your org here>"
trap "break; exit" INT
readarray -t LINES < <(hammer --output csv host-collection list --organization ${ORG})
for (( i=1; i<${#LINES[@]}; i++))
do
IFS="," VALS=(${LINES[$i]})
echo
echo "${VALS[1]} (${VALS[3]})"
hammer host list --search "host_collection = ${VALS[1]}" --organization ${ORG}
done
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
