Skip to content

Instantly share code, notes, and snippets.

@jonathanmedd
Last active March 4, 2020 18:19
Show Gist options
  • Save jonathanmedd/f5a5dd36e7332e10b808b7d6c4b48d77 to your computer and use it in GitHub Desktop.
Save jonathanmedd/f5a5dd36e7332e10b808b7d6c4b48d77 to your computer and use it in GitHub Desktop.
_test_pwsh7
---
- hosts: all
tasks:
- name: Run a script
shell: "{{ playbook_dir }}/files/test_output4.ps1"
args:
executable: /usr/bin/pwsh
register: result1
- name: Process output
set_fact:
errorDetail: "{{ result1.stdout | from_json }}"
- debug:
msg: "Error Category: {{ errorDetail.Category }}, Error Activity: {{ errorDetail.Activity }}, Error Reason: {{ errorDetail.Reason }} for Target {{ errorDetail.TargetName }}"
- name: Invoke-RestMethod via shell module
shell: Invoke-RestMethod -Uri 'https://httpbin.org/get' | ConvertTo-Json
args:
executable: /usr/bin/pwsh
register: apiRequest
- name: Process output
set_fact:
apiOutput: "{{ apiRequest.stdout | from_json }}"
- debug:
msg: "The User-Agent used to make the API request was {{ apiOutput.headers['User-Agent'] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment