Update Sharepoint.yaml
This commit is contained in:
@@ -133,33 +133,56 @@
|
||||
msg:
|
||||
names: "{{ (cols_probe.json.value | default([])) | map(attribute='name') | list }}"
|
||||
|
||||
# --- Create list item ---
|
||||
# --- Create list item (no block/rescue; use ignore_errors + diagnostics) ---
|
||||
- name: Create SharePoint list item (Graph)
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
block:
|
||||
- uri:
|
||||
url: "https://graph.microsoft.com/v1.0/sites/{{ site_id }}/lists/{{ list_id }}/items"
|
||||
method: POST
|
||||
headers:
|
||||
Authorization: "Bearer {{ graph_token.json.access_token }}"
|
||||
Content-Type: "application/json"
|
||||
body_format: json
|
||||
return_content: true
|
||||
status_code: [200, 201]
|
||||
body:
|
||||
fields:
|
||||
Title: "{{ job_name }} ({{ job_id }})"
|
||||
Status: "{{ status }}"
|
||||
RunStart: "{{ run_start }}"
|
||||
RunEnd: "{{ run_end }}"
|
||||
Notes: |-
|
||||
{{ summary_text }}
|
||||
Recap: {{ hostvars['localhost'].recap_line }}
|
||||
register: sp_create
|
||||
no_log: true
|
||||
uri:
|
||||
url: "https://graph.microsoft.com/v1.0/sites/{{ site_id }}/lists/{{ list_id }}/items"
|
||||
method: POST
|
||||
headers:
|
||||
Authorization: "Bearer {{ graph_token.json.access_token }}"
|
||||
Content-Type: "application/json"
|
||||
body_format: json
|
||||
return_content: true
|
||||
status_code: [200, 201]
|
||||
body:
|
||||
fields:
|
||||
Title: "{{ job_name }} ({{ job_id }})"
|
||||
Status: "{{ status }}"
|
||||
RunStart: "{{ run_start }}"
|
||||
RunEnd: "{{ run_end }}"
|
||||
Notes: |-
|
||||
{{ summary_text }}
|
||||
Recap: {{ hostvars['localhost'].recap_line }}
|
||||
register: sp_create
|
||||
ignore_errors: true
|
||||
no_log: true
|
||||
|
||||
rescue:
|
||||
- name: Sanitize and print the error
|
||||
run_once: true
|
||||
- name: Show sanitized Graph error (if any)
|
||||
run_once: true
|
||||
when: sp_create is failed
|
||||
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.
|
||||
|
||||
- name: Fail if SharePoint item was not created
|
||||
run_once: true
|
||||
when: sp_create is failed
|
||||
fail:
|
||||
msg: "Failed to create SharePoint item (see previous message)."
|
||||
|
||||
- name: Show created list item id
|
||||
run_once: true
|
||||
when: sp_create is succeeded
|
||||
debug:
|
||||
var: sp_create.json.id
|
||||
Reference in New Issue
Block a user