Skip to content

Commit

Permalink
Added removal for Azure App and SP (#8954)
Browse files Browse the repository at this point in the history
* Added removal for Azure App and SP

* Added removal for Azure App and SP

* Added become: yes

* Added MS gpg key verification

* Added MS gpg key verification

---------

Co-authored-by: Ritesh <[email protected]>
  • Loading branch information
ritzshah and rshah-redhat authored Jan 8, 2025
1 parent 1794c8f commit 3094df0
Showing 1 changed file with 83 additions and 4 deletions.
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

0 comments on commit 3094df0

Please sign in to comment.