Uninstall Netprobe

The UninstallNetprobe.yaml CloudFormation template uninstalls the Netprobe on existing EC2 instances.

Prerequisites Copied

xxx

Input Parameters Copied

xxx

Configuration Copied

AWSTemplateFormatVersion: '2010-09-09'
Description: Uninstall Netprobe on existing EC2 instances using AWS Systems Manager

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
    - Label:
        default: "Target EC2 Configuration"
      Parameters:
      - InstanceIds
    - Label:
        default: "AWS Credentials"
      Parameters:
      - AWSRegion
    - Label:
        default: "Netprobe Configuration"
      Parameters:
      - NetprobeInstallDirectory
    ParameterLabels:
      InstanceIds:
        default: "Target EC2 Instance IDs"
      AWSRegion:
        default: "AWS Region"
      NetprobeInstallDirectory:
        default: "Netprobe Installation Directory"

Parameters:
  InstanceIds:
    Type: CommaDelimitedList
    Description: Comma-separated list of existing EC2 Instance IDs

  AWSRegion:
    Type: String
    Description: AWS Region for CLI configuration (e.g., ap-southeast-1, us-west-2)
    Default: ap-southeast-1

  NetprobeInstallDirectory:
    Type: String
    Description: Directory where Netprobe was installed
    Default: "~/geneos"

Resources:
  NetprobeUninstallDocument:
    Type: AWS::SSM::Document
    Properties:
      DocumentType: Command
      DocumentFormat: YAML
      Content:
        schemaVersion: '2.2'
        description: Uninstall Netprobe
        parameters:
          AWSRegion:
            type: String
            description: AWS Region
          NetprobeInstallDirectory:
            type: String
            description: Netprobe installation directory
        mainSteps:
        - action: aws:runShellScript
          name: uninstallNetprobe
          inputs:
            timeoutSeconds: '3600'
            runCommand:
            - |
              #!/bin/bash
              set -e
              
              echo "=== Starting Netprobe Uninstall ==="
              
              # Identify OS and version
              echo "--- Identifying OS and version ---"
              if [ -f /etc/os-release ]; then
                . /etc/os-release
                OS=$ID
                VERSION_ID=$VERSION_ID
              elif [ -f /etc/redhat-release ]; then
                OS=$(awk '{print tolower($1)}' /etc/redhat-release)
                VERSION_ID=$(awk '{print $3}' /etc/redhat-release)
              else
                echo "ERROR: Unsupported OS"
                exit 1
              fi
              echo "Detected OS: $OS $VERSION_ID"
              
              # Detect default user
              if [ "$OS" = "ubuntu" ]; then
                DEFAULT_USER="ubuntu"
              else
                DEFAULT_USER="ec2-user"
              fi
              echo "Default user: $DEFAULT_USER"
              
              # Check if SSM agent user exists, fallback to detected user
              if id "ssm-user" &>/dev/null; then
                INSTALL_USER="ssm-user"
              else
                INSTALL_USER="$DEFAULT_USER"
              fi
              echo "Installation user: $INSTALL_USER"
              
              # Set default values for optional parameters if they're empty
              AWS_REGION="{{AWSRegion}}"
              if [ -z "$AWS_REGION" ]; then
                AWS_REGION="ap-southeast-1"
              fi
              export AWS_DEFAULT_REGION="$AWS_REGION"
              
              # Parse the netprobe install directory (handle ~ expansion)
              NETPROBE_DIR="{{NetprobeInstallDirectory}}"
              if [ -z "$NETPROBE_DIR" ]; then
                NETPROBE_DIR="~/geneos"
              fi
              if [[ "$NETPROBE_DIR" == ~* ]]; then
                NETPROBE_DIR=${NETPROBE_DIR:1}
                NETPROBE_DIR="/home/$INSTALL_USER$NETPROBE_DIR"
              fi
              
              sudo systemctl stop netprobe.service || true
              sudo rm -rf "$NETPROBE_DIR/netprobe"
              sudo rm -rf "$NETPROBE_DIR/backup"
              sudo rm -rf "$NETPROBE_DIR/netprobe.tar.gz"
              sudo rm -rf /etc/systemd/system/netprobe.service
              
              echo "=== Netprobe Uninstall Complete ==="

  NetprobeUninstallByInstanceIds:
    Type: AWS::SSM::Association
    Properties:
      Name: !Ref NetprobeUninstallDocument
      Targets:
      - Key: InstanceIds
        Values: !Ref InstanceIds
      Parameters:
        AWSRegion:
        - !Ref AWSRegion
        NetprobeInstallDirectory:
        - !Ref NetprobeInstallDirectory

Outputs:
  SSMDocumentName:
    Description: Name of the SSM Document created for Netprobe uninstall
    Value: !Ref NetprobeUninstallDocument
    Export:
      Name: !Sub "${AWS::StackName}-UninstallSSMDocument"

  AssociationId:
    Description: SSM Association ID for the Netprobe uninstall
    Value: !Ref NetprobeUninstallByInstanceIds
    Export:
      Name: !Sub "${AWS::StackName}-UninstallAssociationId"
["Geneos"] ["Geneos > Netprobe"] ["User Guide"]

Was this topic helpful?