linux_wiki:freeipa_report_hosts_ungrouped

FreeIPA: Report Hosts Ungrouped

General Information

Report IPA hosts that are not in any groups.

Checklist


The Script

report-hosts-ungrouped.sh
#!/bin/bash
# Name: report-hosts-ungrouped.sh
# Description: Report Ungrouped Systems
# Last Modified: 2016-10-07
# Recent Changes:-Updated usage and name
#                -Updated temp file paths for production use
###############################################################################################
 
##### Customize These Variables #####
# IPA admin user
admin_user="admin"
 
# Temp Files Used
systems_in_groups="/root/ldap-scripts/tmp/report-hosts-ungrouped_systemsingroups.log"
all_systems="/root/ldap-scripts/tmp/report-hosts-ungrouped_allsystems.log"
##### End of Customize Variables #####
 
#=====================================
# Functions; Main starts after
#=====================================
function show_usage
{
  echo -e "\n==== Report: Ungrouped Systems ===="
  echo -e "\nDescripton: Report systems that are not in any host-group."
  echo -e "\n--Usage--"
  echo -e "./report-hosts-ungrouped.sh [OPTIONS]"
  echo -e "\n-OPTIONS-"
  echo -e "-h                    => Display usage."
  echo -e "\n--Other Requirements--"
  echo -e "-> FreeIPA admin access."
  echo -e
}
 
#=======================
# Get Script Arguments
#=======================
# Reset POSIX variable in case it has been used previously in this shell
OPTIND=1
 
while getopts "h" opt; do
  case "${opt}" in
    h) # -h (help) argument
      show_usage
      exit 0
    ;;
    *) # invalid argument
      show_usage
      exit 0
    ;;
  esac
done
 
#===================
# Pre-checks: Make sure we have good options set
#===================
# See if we have a kerberos ticket, if not, prompt login
/usr/bin/klist -s
if [[ $? -ne 0 ]]; then
  echo ">>No kerberos ticket found for (${admin_user}), login as ${admin_user} now:"
  /usr/bin/kinit ${admin_user}
  echo
fi
 
#===================
# Main starts here
#===================
echo -e "======================================================"
echo -e "####========= Report: Ungrouped Systems ==========####"
echo -e "======================================================"
echo
echo -e "This script will report all systems that are not in any FreeIPA host-groups."
echo -e "=>Continue?[y/n]:\c"
read run_script
 
if [[ ${run_script} != "y" ]]; then
  echo -e "\n>>Will not run the Report Ungrouped Systems script. Exiting..."
  exit 1
fi
 
# Get all systems with groups
echo -e "\n>> Finding all systems with groups..."
ipa host-find --sizelimit=0 --in-hostgroups='' | grep -E "(Host|host-groups)" | awk '/host-groups/ { print myname }; { myname=$3 }' > ${systems_in_groups}
 
# Get all systems
echo -e ">> Getting all systems..."
ipa host-find --sizelimit=0 --in-hostgroups='' | grep "Host" | awk '{print $3}' > ${all_systems}
 
# Compare the two files: Display systems with no group
echo -e "\n>> Ungrouped Systems:"
diff -u ${systems_in_groups} ${all_systems} | grep ^+ | grep -v ${all_systems} | sed 's/+//'
 
echo -e "\n=========================================="
echo -e "=- Report: Ungrouped Systems Completed. -="
echo -e "=========================================="

  • linux_wiki/freeipa_report_hosts_ungrouped.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)