--- /dev/null
+---
+# Build a FRESH OAuth header using the pre-encoded pieces from api_auth_pretasks.yml.
+# Requires: maas_ck_enc, maas_tk_enc, maas_sig_enc
+
+- name: Build OAuth header (fresh nonce/timestamp)
+ vars:
+ _nonce: "{{ lookup('community.general.random_string', length=24, upper=false, special=false) }}"
+ _ts: "{{ lookup('pipe', 'date +%s') }}"
+ set_fact:
+ maas_auth_header: >-
+ OAuth oauth_version="1.0",
+ oauth_signature_method="PLAINTEXT",
+ oauth_consumer_key="{{ maas_ck_enc }}",
+ oauth_token="{{ maas_tk_enc }}",
+ oauth_signature="{{ maas_sig_enc }}",
+ oauth_nonce="{{ _nonce | urlencode }}",
+ oauth_timestamp="{{ _ts }}"
+ no_log: true
--- /dev/null
+---
+# Parse the MAAS API key ONCE and pre-encode the static OAuth pieces.
+# The key can come from either MAAS_{POK|TUC}_API_KEY in your env (via group_vars/maas.yml)
+# or the "Get API key" task in roles/maas/tasks/main.yml
+
+- name: Bail if no MAAS key
+ assert:
+ that:
+ - maas_api_key is defined
+ - (maas_api_key | length) > 0
+ fail_msg: "maas_api_key not available."
+
+# Split key: <consumer_key>:<token_key>:<token_secret>
+- name: Parse MAAS API key once
+ set_fact:
+ maas_ck_raw: "{{ (maas_api_key.split(':'))[0] }}"
+ maas_tk_raw: "{{ (maas_api_key.split(':'))[1] }}"
+ maas_ts_raw: "{{ (maas_api_key.split(':'))[2] }}"
+ no_log: true
+
+# Pre-encode static values used in every header
+- name: Pre-encode OAuth static pieces
+ set_fact:
+ maas_ck_enc: "{{ maas_ck_raw | urlencode }}"
+ maas_tk_enc: "{{ maas_tk_raw | urlencode }}"
+ maas_sig_enc: "{{ ('&' ~ maas_ts_raw) | urlencode }}"
+ no_log: true
# Configure MAAS
- import_tasks: config_maas.yml
+- import_tasks: api_auth_pretasks.yml
+ tags:
+ - always
+ - api
+
# Configure NTP Service
- import_tasks: config_ntp.yml