-
-
Save alexbmw00/6e77caeb8ef6fb41f2752cdebed5b805 to your computer and use it in GitHub Desktop.
This is a quick Ansible script to setup a machine remotely for PSRP with Ansible using PsExec, then switching to PSRP native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - name: Setup Windows machine with Ansible | |
| hosts: all | |
| gather_facts: false | |
| pre_tasks: | |
| - name: Setup WinRM, PSRP | |
| community.windows.psexec: | |
| hostname: '{{ hostvars[inventory_hostname]["ansible_host"] | default(inventory_hostname) }}' | |
| connection_username: '{{ ansible_user }}' | |
| connection_password: '{{ ansible_password }}' | |
| encrypt: yes | |
| executable: powershell.exe | |
| arguments: '-' | |
| stdin: | | |
| Set-ExecutionPolicy Bypass -Scope LocalMachine -Force | |
| [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
| $url = "https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1" | |
| $file = "$env:temp\ConfigureRemotingForAnsible.ps1" | |
| (New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) | |
| Invoke-Expression "$file -SkipNetworkProfileCheck" | |
| exit | |
| delegate_to: localhost | |
| changed_when: false | |
| - name: Gathering facts | |
| setup: | |
| post_tasks: | |
| - name: Reset ExecutionPolicy | |
| ansible.windows.win_powershell: | |
| script: Set-ExecutionPolicy Undefined -Scope LocalMachine -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment