---
- name: Enable SSH
hosts: windows
vars:
pub_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCoxsL0gMrzfa7l1UptsW9KwkV0W4KTs57Tx5LDWfzWT0yQRH4L9pt+T/P7uiBvBqxNOPlu5+1hGcfd8aBvvCrKhWazPHuDCwEaPrzqr1KH1x+Kb0+/KrRB+IAwLElgHqEK3+pPomaBXdIn4LcIyhtmfk1XMN/IQRVfpIRV7DZZ6SGI5ZEww+dHwZlu4/JTMeRfBX7oAt4LeXWbx74Vx4PBibMBADPzu/zS0z0IMwJAhnIr5mmadhwCe5S+Pm0QrIZGhXVRIkiYM9zvS+CPp6R4wFXk+SenH7jkroC90iWXL4iBILIPz40uf7mNyLTq7/O7J0NirGAy4LEVQ8GDHCLJI4QRxsa0nsiVS1C9Jx7UFeOktjeFtarUe+ha2DXXb+eF8pOCbSbp6NN0j4Q23V/HHRadARZLuGCYyglxrnQgEnjZ1aXrIB3hLCQoGSbCJDGr0YoQEGSZ3qe9+YXt/yx+z3KhRWXEeFI+2MwhtFVl6D8dsqA9YV5r8bkoqCqJA+8= jdelapor@jdelapor-mac
tasks:
- name: Run the jborean Powershell update script
#Note: This will log the password in plaintext!
ansible.windows.win_powershell:
script: |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1"
$file = "$env:temp\Upgrade-PowerShell.ps1"
$username = "Administrator"
$password = "{{ ansible_password }}"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
# Version can be 3.0, 4.0 or 5.1
&$file -Version 5.1 -Username $username -Password $password -Verbose
- name: install the Win32-OpenSSH service
win_chocolatey:
name: openssh
package_params: /SSHServerFeature
state: present
- name: Run jborean win_ssh role
ansible.builtin.include_role:
name: jborean93.win_openssh
vars:
opt_openssh_pubkeys: "{{ pub_keys }}"
- name: set the default shell to PowerShell
win_regedit:
path: HKLM:\SOFTWARE\OpenSSH
name: DefaultShell
data: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
type: string
state: present
- name: Declare victory
debug:
msg: "You should now be able to ssh to user@host, eg. {{ ansible_user }}@{{ ansible_host }}, or user@domain@IP"
Copyright 2019-2023 Joanna Delaporte