How to run the Licenseware Collector for Red Hat Deployment Manager Script

Understand how to run the Collector script for RDM on one or multiple devices at the same time

0. Download the script

The script is available for Licenseware customers, request access and download the script.

1. Script Overview

The Licenseware Collector for Red Hat Deployment Manager is a versatile script designed to gather comprehensive data about the system and software environment of a Red Hat Enterprise Linux (RHEL) system. The script collects information related to hardware, installed packages, virtual machine status, and subscription details, which can be crucial for managing software assets and ensuring compliance.

2. Information Collected

The script performs the following tasks:

  1. Check for Required Utilities: Ensures all necessary utilities (rpm, lscpu, hostname, systemd-detect-virt, subscription-manager, yum, dnf, flatpak, snap, subscription-manager) are installed.
  2. List Installed Red Hat Add-on Packages: Collects and lists the installed Red Hat add-on packages.
  3. CPU Details: Gathers details about the CPU, including the model, vendor, number of sockets, cores per socket, and total core count.
  4. Device Information: Captures the device name and model.
  5. Virtual Machine Check: Determines if the system is a virtual machine.
  6. OS Install Date: Retrieves the installation date of the OS.
  7. Subscription Status: Checks the Red Hat subscription status and the last refresh timestamp.
  8. Red Hat Middleware Products: Searches and lists installed Red Hat Middleware products.
  9. Package inventory: Collects detailed lists of all installed packages and saves this information to a separate text file.
  10. Script output: Outputs the collected data to a JSON file.

Output files:

  1. Licenseware_Collector_RHEL_Script_Output_{timestamp}_{hostname}.json
  2. Licenseware_Collector_RHEL_Package_Inventory_{timestamp}_{hostname}.txt

3. Privileges Needed

To successfully run this script, the following privileges are required:

  • Root Privileges: The script should be run as a root user or with sudo privileges. This is necessary to access system information, installed packages, and other details that are typically restricted to root users.
  • Subscription Manager Access: The user should have appropriate permissions to query the Red Hat subscription manager.

4. Executing the Script on a Single Host

  1. Ensure Necessary Privileges:

    • The script requires sudo privileges. Ensure the user running the script has sudo access.
  2. Run the Script:

    • SSH into the target host:
      bash
      Copy code
      ssh username@target_host
    • Navigate to the directory where the script is located and run it with sudo:
      bash
      Copy code
      cd /path/to/directory sudo bash licenseware-collector-rhel-script-v5.sh

5. Executing the Script on Multiple Hosts

5.1. Using SSH with a Shell Script

This method relies on SSH access to each target machine and assumes that the user has the necessary privileges to execute the script with sudo. Additionally, it requires that the local machine has passwordless SSH configured for the target servers, or it will prompt for passwords during the execution.

5.1.1. Steps

  1. Prepare a List of Target Machines: Create a file (servers.txt) that lists the target machines.

    server1.example.com server2.example.com server3.example.com
  2. Create the Shell Script: Write a shell script (run_licenseware_collector.sh) that reads the list of target machines and runs the Licenseware Collector script on each of them using SSH.

    #!/bin/bash

    # Path to the Licenseware Collector script on the local machine
    SCRIPT_PATH="/path/to/licenseware-collector-rhel-script-v5.sh"

    # Path to the Licenseware Collector script on the remote machine
    REMOTE_SCRIPT_PATH="/tmp/licenseware-collector-rhel-script-v5.sh"

    # Path to the file containing the list of servers
    SERVERS_LIST="servers.txt"

    # Loop through each server in the list
    while read -r SERVER; do
        echo "Processing $SERVER..."

        # Copy the Licenseware Collector script to the remote server
        scp "$SCRIPT_PATH" "$SERVER:$REMOTE_SCRIPT_PATH"

        # Execute the script on the remote server
        ssh "$SERVER" "sudo bash $REMOTE_SCRIPT_PATH"

        # Retrieve the JSON output file from the remote server
        ssh "$SERVER" "cat /tmp/Licenseware_Collector_RHEL_Script_Output_*.json" > "/path/to/output/${SERVER}_output.json"

        # Retrieve the package dump file from the remote server
        ssh "$SERVER" "cat /tmp/Licenseware_Collector_RHEL_Package_Inventory_*.txt" > "/path/to/output/${SERVER}_package_dump.txt"

        echo "Completed processing $SERVER"
    done < "$SERVERS_LIST"

    echo "All servers processed."

  3. Run the Shell Script: Execute the shell script on your local machine.

    chmod +x run_licenseware_collector.sh ./run_licenseware_collector.sh

5.1.2. Explanation

  • Servers List: The servers.txt file contains the hostnames or IP addresses of the target machines.
  • Loop Through Servers: The shell script reads each server from servers.txt and performs the following actions:
    • Copy Script: Uses scp to copy the Licenseware Collector script to the remote server.
    • Execute Script: Uses ssh to run the script on the remote server with sudo privileges.
    • Retrieve Outputs: Uses ssh to retrieve the JSON output and package dump files from the remote server to the local machine.

5.2 Using Ansible

To execute the script on multiple machines simultaneously, tools like Ansible, Puppet, or other configuration management tools can be used. Below is an example of how to use Ansible to run the script on multiple RHEL machines.

5.2.1. Steps

  1. Prepare the Inventory File: Create an inventory file (hosts) with the list of target machines.
    [rhel_servers] server1.example.com server2.example.com

  2. Create the Ansible Playbook: Create a playbook (run_licenseware_collector.yml) to copy the script to target machines and execute it.

    ---
    - name: Run Licenseware Collector on RHEL Servers
      hosts: rhel_servers
      become: yes

      tasks:
        - name: Copy the Licenseware Collector script to the remote server
          copy:
            src: /path/to/licenseware-collector-rhel-script-v5.sh
            dest: /tmp/licenseware-collector-rhel-script-v5.sh
            mode: '0755'

        - name: Execute the Licenseware Collector script
          command: sudo /tmp/licenseware-collector-rhel-script-v5.sh
          register: script_output

        - name: Save the script output to a local file
          local_action:
            module: copy
            content: ""
            dest: "/path/to/output/_output.txt"
  3. Run the Playbook: Execute the playbook using the following command.

    ansible-playbook -i hosts run_licenseware_collector.yml

5.2.2. Explanation

  • Inventory File: Lists the RHEL servers where the script will be executed.
  • Playbook Tasks:
    • Copy Script: Transfers the Licenseware Collector script to the target machines.
    • Execute Script: Runs the script on the target machines with sudo privileges.
    • Save Output: Collects the script output and saves it to a local file for each server.

By using Ansible, you can efficiently run the Licenseware Collector script on multiple machines simultaneously, streamlining the data collection process across many systems.