Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added removal for Azure App and SP #8954

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,85 @@
---
- name: Remove OLS Operator
become: true # Use become to run tasks with sudo
vars:
tenant_id: "{{ ocp4_workload_ols_azure_tenant_id }}"
client_id: "{{ ocp4_workload_ols_main_client_id }}"
client_secret: "{{ ocp4_workload_ols_main_client_secret }}"
guid: "{{ guid }}"
block:
- name: Remove Operator
when: ocp4_workload_ols_install_operator | bool
include_tasks: remove_ols_operator.yml
- name: Install Microsoft GPG key
rpm_key:
state: present
key: https://packages.microsoft.com/keys/microsoft.asc

- name: Install Microsoft package repository
dnf:
name: https://packages.microsoft.com/config/rhel/9.0/packages-microsoft-prod.rpm
state: present

- name: Install Azure CLI
dnf:
name: azure-cli
state: present

- name: Check Azure CLI version
command: az --version
register: az_version

- name: Display Azure CLI version
debug:
var: az_version.stdout

- name: Create a temporary script file
copy:
dest: /tmp/delete_app_sp.sh
content: |
#!/bin/bash

# Check if a parameter is passed
if [ -z "$1" ]; then
echo "Usage: $0 <value>"
exit 1
fi

# Assign the parameter to a variable
GUID=$1

# Use the parameter in the display name
CHILD_APP_DISPLAY_NAME="RHDP-lightspeed-$GUID"

TENANT_ID="{{ tenant_id }}"
CLIENT_ID="{{ client_id }}"
CLIENT_SECRET="{{ client_secret }}"

az login --service-principal --username "$CLIENT_ID" --password "$CLIENT_SECRET" --tenant "$TENANT_ID"

echo $CHILD_APP_DISPLAY_NAME

# Get app IDs and store them in app_ids.txt
az ad app list --display-name "$CHILD_APP_DISPLAY_NAME" | grep -i appid | cut -d'"' -f4 > app_ids.txt

# Loop through each appId and delete it
while read -r app_id; do
echo "Deleting app with ID: $app_id"
az ad app delete --id "$app_id"
sleep 5 # Delay 5 seconds before next deletion
done < app_ids.txt

- name: Make the script executable
file:
path: /tmp/delete_app_sp.sh
mode: '0755'

- name: Run the script to delete Azure App and Service Principal
command: /tmp/delete_app_sp.sh "{{ guid }}"
args:
chdir: /tmp # Change to /tmp directory before running the script

- name: Clean up temporary script file
file:
path: /tmp/delete_app_sp.sh
state: absent

- name: Remove Operator
when: ocp4_workload_ols_install_operator | bool
include_tasks: remove_ols_operator.yml
Loading