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

Login to Azure using Service Principal #773

Merged
merged 1 commit into from
Sep 25, 2024
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
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
Loading