Skip to content

Commit

Permalink
Move token generation to ansible
Browse files Browse the repository at this point in the history
  • Loading branch information
BillAnastasiadis committed Aug 30, 2024
1 parent 8d5072d commit b3d3bd6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions ansible/playbooks/sap-hana-download-media.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,46 @@
group: root
mode: 0755

- name: Retrieve account key
ansible.builtin.command: >-
az storage account keys list

Check failure on line 28 in ansible/playbooks/sap-hana-download-media.yaml

View workflow job for this annotation

GitHub Actions / build

28:37 [trailing-spaces] trailing spaces
--account-name {{ az_storage_account_name }}

Check failure on line 29 in ansible/playbooks/sap-hana-download-media.yaml

View workflow job for this annotation

GitHub Actions / build

29:53 [trailing-spaces] trailing spaces
--query "[?contains(keyName,'{{ az_key_name }}')].value"

Check failure on line 30 in ansible/playbooks/sap-hana-download-media.yaml

View workflow job for this annotation

GitHub Actions / build

30:65 [trailing-spaces] trailing spaces
-o tsv
delegate_to: 127.0.0.1
run_once: true
register: az_account_key
when: az_sas_token is not defined or az_sas_token == ""

- name: "Set expiry"
ansible.builtin.command: "date -u +'%Y-%m-%dT%H:%MZ' -d '+20 minutes'"
delegate_to: 127.0.0.1
run_once: true
register: expiry
when: az_sas_token is not defined or az_sas_token == ""

- name: Generate SAS token
ansible.builtin.command: >-
az storage container generate-sas \
--account-name {{ az_storage_account_name }} \
--account-key {{ az_account_key.stdout }} \
--name {{ az_container_name.split('/')[0] }} \
--permission r \
--expiry {{ expiry.stdout }} \
--out tsv
delegate_to: 127.0.0.1
changed_when: false
run_once: true
register: az_sas_token_output
when: az_sas_token is not defined or az_sas_token == ""

- name: Set az_sas_token fact
ansible.builtin.set_fact:
az_sas_token: "{{ az_sas_token_output.stdout }}"
delegate_to: 127.0.0.1
run_once: true
when: az_sas_token is not defined or az_sas_token == ""

- name: Download HANA media with SAS token
ansible.builtin.get_url:
url: "https://{{ az_storage_account_name }}.blob.core.windows.net/{{ az_container_name }}/{{ item }}?{{ az_sas_token }}"
Expand Down

0 comments on commit b3d3bd6

Please sign in to comment.