-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparse_as3_dryrun.sh
executable file
·38 lines (33 loc) · 1.22 KB
/
parse_as3_dryrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# example usage:
# ./parse_as3_dryrun.sh [file containing AS3 json output]
# ANSI color codes
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Read the AS3 response from a file generated by Ansible
as3_response=$(cat $1 | jq .traces)
#Look for the Key containing Diff since it is unique and it has appended the TENANT (partition)
#This declaration is pointing.
TENANT=$(echo $as3_response | jq -r 'keys[] | select(contains("Diff"))')
# Debug: Print the JSON to check its validity
#echo "$as3_response"
# Use jq to parse the JSON response and extract change details
# Coloring the words with ANSI color codes
echo -e "${WHITE}The following changes will be performed:${NC}"
echo
echo -e "${GREEN}Create:${NC}"
echo
echo "$as3_response" | jq --arg TENANT "$TENANT" -r '.[$TENANT][] | select(.kind=="N") | "\(.command) - \(.path)"'
echo
echo -e "${BLUE}Modify:${NC}"
echo
echo "$as3_response" | jq --arg TENANT "$TENANT" -r '.[$TENANT][] | select(.kind=="E") | "\(.command) \(.path) - \(.lhs) ===> \(.rhs)"'
echo
echo -e "${RED}Delete:${NC}"
echo
echo "$as3_response" | jq --arg TENANT "$TENANT" -r '.[$TENANT][] | select(.kind=="D") | "\(.command) - \(.path)"'
echo