Last active
March 18, 2025 14:20
-
-
Save chornberger-c2c/00552f6ae7852a4cdc3d4a709603be86 to your computer and use it in GitHub Desktop.
Create a host on Red Hat Satellite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
cat <<EOF | |
Creates a host on a Satellite server | |
Usage: $0 | |
-g, --hostgroup hostgroup ID | |
-h, --host host to create | |
-i, --ip IP address | |
-l, --location_id location ID | |
-o, --org_id organization ID | |
-p, --password password | |
-s, --server Satellite server | |
-u, --user username | |
EOF | |
exit 0 | |
} | |
createHost() { | |
curl https://"${SERVER}"/api/hosts/ \ | |
-X POST \ | |
-k \ | |
-H "Content-Type: application/json" \ | |
--user "${USER}":"${PASS}" \ | |
-d "{\"host\":{\"name\":\"${HOST}\",\"location_id\":\"${LOCATION}\",\"organization_id\":\"${ORG}\",\"hostgroup_id\":\"${HOSTGROUP}\",\"build\":\"true\",\"managed\":\"true\",\"enabled\":\"true\",\"ip\":\"${IP}\"}}" | |
} | |
parseOptions() { | |
[[ $# -eq 0 ]] && usage | |
while test $# -gt 0; do | |
key="$1" | |
case "${key}" in | |
-h|--host) | |
HOST=${2} | |
shift | |
;; | |
-g|--hostgroup) | |
HOSTGROUP=${2} | |
shift | |
;; | |
-i|--ip) | |
IP=${2} | |
shift | |
;; | |
-l|--location_id) | |
LOCATION=${2} | |
shift | |
;; | |
-o|--org_id) | |
ORG=${2} | |
shift | |
;; | |
-p|--password) | |
PASS=${2} | |
shift | |
;; | |
-s|--server) | |
SERVER=${2} | |
shift | |
;; | |
-u|--user) | |
USER=${2} | |
shift | |
;; | |
*) | |
usage | |
;; | |
esac | |
shift | |
done | |
} | |
main() { | |
parseOptions "$@" | |
createHost | |
exit 0 | |
} | |
main "$@" || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment