Powershell templates (#5)

Windows Powershell Demos
This commit is contained in:
MKletz
2022-02-23 11:01:02 -06:00
committed by GitHub
parent 2041667534
commit 788cf7b675
4 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
---
- name: Arbitrary PowerShell
hosts: "{{ HOSTS | default('windows') }}"
gather_facts: false
vars:
ps_script: undef
tasks:
- name: Run PowerShell
ansible.windows.win_powershell:
script: |
{{ ps_script }}
register: ps_output
- debug:
msg: "{{ ps_output.output }}"

View File

@@ -0,0 +1,20 @@
---
- name: PowerShell Script
hosts: "{{ HOSTS | default('windows') }}"
gather_facts: false
vars:
remote_dest: "C:\\sample_script.ps1"
tasks:
- name: Copy script to remote
ansible.windows.win_copy:
src: "{{playbook_dir}}/sample_script.ps1"
dest: "{{ remote_dest }}"
- name: Run Script
ansible.windows.win_powershell:
script: |
{{ remote_dest }} -ServiceState {{ service_state }}
register: ps_output
- debug:
var: ps_output

View File

@@ -0,0 +1,7 @@
Param
(
[Parameter(Mandatory=$true)]
[string]$ServiceState
)
# Sample parameterized script for use with powershell_script.yml
Get-Service | Where-Object -FilterScript {$_.Status -eq $ServiceState} | Select-Object -Property 'Name'

View File

@@ -114,3 +114,52 @@ controller_templates:
type: text
variable: package_name
required: true
- name: "WINDOWS / Arbitrary PowerShell"
job_type: run
inventory: "Workshop Inventory"
project: "Ansible official demo project"
playbook: "windows/arbitrary_powershell.yml"
execution_environment: Default execution environment
credentials:
- "Workshop Credential"
survey_enabled: true
survey:
name: ''
description: ''
spec:
- question_name: Server Name or Pattern
type: text
variable: HOSTS
required: false
- question_name: PowerShell Script (Default returns random cat fact)
type: textarea
variable: ps_script
default: "(Invoke-RestMethod -Method 'GET' -Uri 'https://catfact.ninja/fact').fact"
required: true
- name: "WINDOWS / PowerShell Script"
job_type: run
inventory: "Workshop Inventory"
project: "Ansible official demo project"
playbook: "windows/powershell_script.yml"
execution_environment: Default execution environment
credentials:
- "Workshop Credential"
survey_enabled: true
survey:
name: ''
description: ''
spec:
- question_name: Server Name or Pattern
type: text
variable: HOSTS
required: false
- question_name: Service state to query?
type: multiplechoice
variable: service_state
required: false
default: 'Running'
choices:
- 'Running'
- 'Stopped'