From 3252db4505b4d9373d0c39a0e3685a9d6305b923 Mon Sep 17 00:00:00 2001 From: mhorak Date: Thu, 14 Aug 2025 07:39:25 +0000 Subject: [PATCH] Update Sharepoint.yaml --- Sharepoint.yaml | 78 +++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 29 deletions(-) diff --git a/Sharepoint.yaml b/Sharepoint.yaml index 127e473..0bce951 100644 --- a/Sharepoint.yaml +++ b/Sharepoint.yaml @@ -16,7 +16,7 @@ job_url: "{{ tower_job_url | default('') }}" status: "{{ (tower_job_failed | default(false)) | ternary('failed','successful') }}" - # Timestamps (avoid ansible_date_time since gather_facts: false) + # Timestamps (works without gather_facts) run_start: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}" run_end: "{{ lookup('pipe','date -u +%Y-%m-%dT%H:%M:%SZ') }}" @@ -43,6 +43,46 @@ no_log: true failed_when: graph_token.status not in [200] + # --- Get recap from AWX and turn it into flat totals --- + - name: Fetch play recap (playbook_on_stats) + delegate_to: localhost + run_once: true + uri: + url: "{{ lookup('env','AWX_API_URL') }}/api/v2/jobs/{{ tower_job_id }}/job_events/?event=playbook_on_stats" + method: GET + headers: + Authorization: "Bearer {{ lookup('env','AWX_API_TOKEN') }}" + Content-Type: "application/json" + return_content: true + status_code: 200 + register: _recap + no_log: true + + - name: Parse recap totals + run_once: true + vars: + stats: "{{ (_recap.json.results | default([])) | first | default({}) }}" + data: "{{ stats.event_data | default({}) }}" + set_fact: + recap_ok: "{{ (data.ok | default({})) | dict2items | map(attribute='value') | map('int') | sum }}" + recap_changed: "{{ (data.changed | default({})) | dict2items | map(attribute='value') | map('int') | sum }}" + recap_failed: "{{ (data.failures | default({})) | dict2items | map(attribute='value') | map('int') | sum }}" + recap_skipped: "{{ (data.skipped | default({})) | dict2items | map(attribute='value') | map('int') | sum }}" + recap_unreach: "{{ (data.dark | default({})) | dict2items | map(attribute='value') | map('int') | sum }}" + + - name: Build SharePoint recap line (store on localhost for later use) + run_once: true + delegate_to: localhost + delegate_facts: true + set_fact: + recap_line: >- + OK={{ recap_ok | default(0) }}, + Changed={{ recap_changed | default(0) }}, + Failed={{ recap_failed | default(0) }}, + Skipped={{ recap_skipped | default(0) }}, + Unreachable={{ recap_unreach | default(0) }} + + # --- Optional probes (keep while debugging) --- - name: Verify siteId resolves delegate_to: localhost run_once: true @@ -67,7 +107,7 @@ return_content: true status_code: 200 register: lists_probe - no_log: false + no_log: true - name: Show lists (sanitized) run_once: true @@ -85,18 +125,15 @@ return_content: true status_code: 200 register: cols_probe - no_log: false - - - name: Print internal names - run_once: true - debug: - var: cols_probe.json.value | map(attribute='name') | list + no_log: true - name: Show internal column names (safe) + run_once: true debug: msg: names: "{{ (cols_probe.json.value | default([])) | map(attribute='name') | list }}" + # --- Create list item --- - name: Create SharePoint list item (Graph) delegate_to: localhost run_once: true @@ -116,29 +153,12 @@ Status: "{{ status }}" RunStart: "{{ run_start }}" RunEnd: "{{ run_end }}" - Notes: "{{ summary_text }}" + Notes: |- + {{ summary_text }} + Recap: {{ hostvars['localhost'].recap_line }} register: sp_create - no_log: false + no_log: true rescue: - name: Sanitize and print the error run_once: true - vars: - _json: "{{ sp_create.json | default({}) }}" - debug: - msg: - status: "{{ sp_create.status | default('n/a') }}" - graph_error: >- - {{ _json.error.message - | default(_json.message - | default(sp_create.msg | default('Unknown error'))) }} - hint: > - 400: column internal names; 401: scope/audience; 403: permissions; - 404: siteId/listId. - - fail: - msg: "Failed to create SharePoint item (see previous message)." - - - name: Show created list item id - run_once: true - debug: - var: sp_create.json.id