Skip to content

Instantly share code, notes, and snippets.

@jonathanmedd
Created December 5, 2019 14:22
Show Gist options
  • Save jonathanmedd/43833962befd4feea0b7408483fc630c to your computer and use it in GitHub Desktop.
Save jonathanmedd/43833962befd4feea0b7408483fc630c to your computer and use it in GitHub Desktop.
local_pwsh
---
- hosts: all
tasks:
- name: Get-Processes via command module
command: pwsh -Command "Get-Process | ConvertTo-Json"
register: processData
- name: Process output
set_fact:
processes: "{{ processData.stdout | from_json }}"
- debug:
msg: "The first process found was {{ processes[0].Name }}"
- 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