Skip to content

Instantly share code, notes, and snippets.

@Richard-Barrett
Created October 20, 2021 15:06
Show Gist options
  • Save Richard-Barrett/7eb3a449f18ae36423062393a15ec58f to your computer and use it in GitHub Desktop.
Save Richard-Barrett/7eb3a449f18ae36423062393a15ec58f to your computer and use it in GitHub Desktop.
Interactive Script To Download The Miratnis MKE config.toml File
#!/bin/bash
# =============================================
# Created by: Richard Barrett
# Date Created: 10/20/2021
# Purpose: Auto MKE Config TOML Download
# Company: Mirantis
# =============================================
# Documentation:
# ========================================================================================
# https://docs.mirantis.com/mke/3.4/ops/administer-cluster/mke-configuration-file.html
# ========================================================================================
#set -e
# keep track of the last executed command
#trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
#trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT
# System Variables
# ================
DATE="$(date +'%Y%-m%d')"
AUTHTOKEN=$(curl -sk -d '{"username":"$USERNAME","password":"$PASSWORD"}' ${REQUEST_URL}/auth/login | jq -r .auth_token)
# Grab Token
# =====================
echo "Would you like to collect kubernetes cluster information (yes/no)?
read ANS
echo "What is your MKE/UCP username?"
read USERNAME
echo "What is your MKE/UCP password?"
read PASSWORD
echo "What is the MKE/UCP IP Address?"
read MKE_IP
while true; do
read -p "Do you want to download the MKE config.toml file (yes/no)?" yn
case $yn in
[Yy]* ) echo "==================================="; \
echo " Collecting CONFIG.TOML..."; \
echo "==================================="; \
# Get MKE Client Bundle and Create Bundle in Working Directory as hostname_bundle_date
cd ~;
# Make Config Directory
echo "Making a config directory...";
mkdir $(pwd)/$hostname_config_$DATE;
echo "Moving into config directory...";
cd $(pwd)/$hostname_config_$DATE;
echo "Grabbing authtoken...";
AUTHTOKEN=$(curl -sk -d '{"username":"$USERNAME","password":"$PASSWORD"}' https://$MKE_IP/auth/login | jq -r .auth_token);
curl --silent --insecure -X GET "https://$MKE_IP/api/ucp/config-toml" -H "accept: application/toml" -H "Authorization: Bearer $AUTHTOKEN" > ucp-config.toml
echo "config file downloaded in $(pwd)/$hostname_config_$DATE...";
cd `;
echo "======================================================================="; \
echo " Downloaded CONFIG.TOML $(pwd)/$hostname_config_$DATE..."; \
echo "======================================================================="; \
break;; \
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment