Trace: ansible_rhel_8

Ansible on RHEL 8 with Windows 10

Install

sudo yum install python36
pip3 install --user ansible
pip3 install --user pywinrm

Windows Configuration

Create a Windows user with password.

# This isn't needed but is a good security practice to complete
Set-ExecutionPolicy -ExecutionPolicy Restricted -Force

$reg_winlogon_path = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon"
Set-ItemProperty -Path $reg_winlogon_path -Name AutoAdminLogon -Value 0
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultUserName -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultPassword -ErrorAction SilentlyContinue

WinRM Setup

$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\ConfigureRemotingForAnsible.ps1"
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
powershell.exe -ExecutionPolicy ByPass -File $file -EnableCredSSP

Test

Enter-PSSesion -ComputerName 192.168.122.166 -Credential ansible -UseSSL -SessionOption New-PSSessionOption -SkipCACheck -SkipCNCheck

Ansible

Create inventory:

[windows]
DESKTOP-8KM1PCG

[windows:vars]
ansible_user=ansible
ansible_password=C00LP4SSW0RD
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=credssp

Run a test ping:

ansible windows -i /path/to/inventory/for/windows -m win_ping

Get IP Address via cmd:

ansible windows -i windows -m win_command -a "ipconfig"

Get list of users via powershell:

ansible windows -i windows -m win_shell -a "Get-LocalUser"

References

ansible_rhel_8.txt · Last modified: 2020/04/29 10:04
Public Domain Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain