16
windows/arbitrary_powershell.yml
Normal file
16
windows/arbitrary_powershell.yml
Normal 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 }}"
|
||||
20
windows/powershell_script.yml
Normal file
20
windows/powershell_script.yml
Normal 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
|
||||
7
windows/sample_script.ps1
Normal file
7
windows/sample_script.ps1
Normal 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'
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user