Open gautam-y opened 3 months ago
#!/bin/bash
# Set the API URL and authentication credentials
API_URL="https://url/api/v2"
AUTH_TOKEN="your_auth_token"
# Set the input file containing organization IDs
INPUT_FILE="org_ids.txt"
# Set the output CSV file
OUTPUT_FILE="instance_groups.csv"
# Create the output file and write the header row
echo "Organization ID,Instance Group Name" > "$OUTPUT_FILE"
# Loop through each organization ID in the input file
while read -r ORG_ID; do
# Make the API call to retrieve the instance group name
RESPONSE=$(curl -s -X GET -H "Authorization: Bearer $AUTH_TOKEN" "$API_URL/organizations/$ORG_ID/instance_groups/")
# Extract the instance group name from the API response
INSTANCE_GROUP_NAME=$(echo "$RESPONSE" | grep -o '"name":"[^"]*' | cut -d':' -f2 | tr -d '"')
# Write the organization ID and instance group name to the output file
echo "$ORG_ID,$INSTANCE_GROUP_NAME" >> "$OUTPUT_FILE"
done < "$INPUT_FILE"
echo "Instance group names exported to $OUTPUT_FILE"
#!/bin/bash
# Set the API URL and authentication credentials
API_URL="https://url/api/v2"
AUTH_TOKEN="your_auth_token"
# Set the input file containing organization IDs
INPUT_FILE="org_ids.txt"
# Set the output CSV file
OUTPUT_FILE="instance_groups.csv"
# Create the output file and write the header row
echo "Organization ID,Instance Group Name" > "$OUTPUT_FILE"
# Loop through each organization ID in the input file
while read -r ORG_ID; do
# Make the API call to retrieve the instance group name
RESPONSE=$(curl -s -X GET -H "Authorization: Bearer $AUTH_TOKEN" "$API_URL/organizations/$ORG_ID/instance_groups/")
# Extract the instance group name from the API response
INSTANCE_GROUP_NAME=$(echo "$RESPONSE" | grep -o '"name":"[^"]*' | cut -d':' -f2 | tr -d '"')
# Check if an instance group name was found
if [ -z "$INSTANCE_GROUP_NAME" ]; then
INSTANCE_GROUP_NAME="No Instance Group"
fi
# Write the organization ID and instance group name to the output file
echo "$ORG_ID,$INSTANCE_GROUP_NAME" >> "$OUTPUT_FILE"
done < "$INPUT_FILE"
echo "Instance group names exported to $OUTPUT_FILE"
TOWER_URL="https://your-ansible-tower-url.com/api/v2" AUTH_HEADER="Authorization: Bearer YOUR_ACCESS_TOKEN"
OUTPUT_FILE="team_details.csv"
echo "team_name,team_id,organization_name,object_role,object_name" > $OUTPUT_FILE
get_organization_name() { ORG_ID=$1 ORG_NAME=$(curl -s -H "$AUTH_HEADER" "${TOWER_URL}/organizations/${ORG_ID}/" | jq -r '.name') echo $ORG_NAME }
while read -r TEAM_ID; do if [[ ! -z "$TEAM_ID" ]]; then echo "Fetching details for team ID: $TEAM_ID"
# Fetch team details
TEAM_RESPONSE=$(curl -s -H "$AUTH_HEADER" "${TOWER_URL}/teams/${TEAM_ID}/")
TEAM_NAME=$(echo $TEAM_RESPONSE | jq -r '.name')
ORG_ID=$(echo $TEAM_RESPONSE | jq -r '.organization')
ORG_NAME=$(get_organization_name $ORG_ID)
# Fetch roles for the given team ID
ROLES_RESPONSE=$(curl -s -H "$AUTH_HEADER" "${TOWER_URL}/teams/$TEAM_ID/roles/")
# Check if the response contains results
if [[ $(echo $ROLES_RESPONSE | jq '.results | length') -gt 0 ]]; then
# Extract role details and append to CSV file
echo $ROLES_RESPONSE | jq -r --arg TEAM_NAME "$TEAM_NAME" --arg TEAM_ID "$TEAM_ID" --arg ORG_NAME "$ORG_NAME" \
'.results[] | [$TEAM_NAME, $TEAM_ID, $ORG_NAME, .name, .summary_fields.content_object.name] | @csv' >> $OUTPUT_FILE
else
echo "No roles found for team ID: $TEAM_ID"
fi
fi
done < teamid.txt
echo "Team details have been exported to $OUTPUT_FILE"
!/bin/bash
Configuration
TOWER_URL="https://YOUR_TOWER_URL/api/v2" USERNAME="YOUR_USERNAME" PASSWORD="YOUR_PASSWORD" OUTPUT_FILE="organizations.csv"
Function to make authenticated API requests
get_api_response() { local url=$1 curl -s -u "$USERNAME:$PASSWORD" "$url" }
Fetch organizations
response=$(get_api_response "$TOWER_URL/organizations/")
Parse JSON response and extract organization details
echo "Name,ID,Instance Group Name" > "$OUTPUT_FILE" echo "$response" | jq -r '.results[] | [.name, .id] | @csv' >> "$OUTPUT_FILE"
Fetch instance groups for each organization
organizations=$(echo "$response" | jq -r '.results[] | [.id] | @csv')
while IFS=',' read -r org_id do
Fetch instance groups for the organization
done <<< "$organizations"
echo "Organizations and instance group details have been exported to $OUTPUT_FILE"