Skip to content

Commit

Permalink
Login to Azure using Service Principal (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Sep 25, 2024
1 parent af9ceff commit ea49eca
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions automation/roles/cloud-resources/tasks/azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,46 @@
PATH: "{{ ansible_env.PATH }}:/usr/local/bin:/usr/bin"
PIP_BREAK_SYSTEM_PACKAGES: "1"

# CLI required for task "Add virtual machine IP addresses to Load Balancer backend pool"
- name: Check if Azure CLI is installed
ansible.builtin.command: az --version
register: az_version_result
changed_when: false
failed_when: false

# try to install CLI (if not installed)
- name: Install Azure CLI
community.general.homebrew:
name: azure-cli
state: present
ignore_errors: true
when:
- az_version_result.rc != 0
- ansible_distribution == "MacOSX"

- name: Install Azure CLI
ansible.builtin.shell: >
set -o pipefail;
curl -sL https://aka.ms/InstallAzureCli | bash
args:
executable: /bin/bash
ignore_errors: true
when:
- az_version_result.rc != 0
- ansible_distribution != "MacOSX"
# Azure CLI
# Note: required for task "Add virtual machine IP addresses to Load Balancer backend pool"
- block:
- name: Check if Azure CLI is installed
ansible.builtin.command: az --version
register: az_version_result
changed_when: false
failed_when: false

# try to install CLI (if not installed)
- name: Install Azure CLI
community.general.homebrew:
name: azure-cli
state: present
ignore_errors: true
when:
- az_version_result.rc != 0
- ansible_distribution == "MacOSX"

- name: Install Azure CLI
ansible.builtin.shell: >
set -o pipefail;
curl -sL https://aka.ms/InstallAzureCli | bash
args:
executable: /bin/bash
ignore_errors: true
when:
- az_version_result.rc != 0
- ansible_distribution != "MacOSX"

# login
- name: Login to Azure using Service Principal
ansible.builtin.shell: |
az login --service-principal \
--username "{{ lookup('env', 'AZURE_CLIENT_ID') }}" \
--password "{{ lookup('env', 'AZURE_SECRET') }}" \
--tenant "{{ lookup('env', 'AZURE_TENANT') }}"
args:
executable: /bin/bash
when: cloud_load_balancer | bool
delegate_to: 127.0.0.1
become: false
run_once: true
Expand Down

0 comments on commit ea49eca

Please sign in to comment.