Ansible on RHEL 6 with Windows 10

Install

yum install libcurl-devel
yum install openssl-devel
su - ansible
pip install ovirt-engine-sdk-python==4.3
subscription-manager repos --enable  rhel-server-rhscl-6-rpms
yum install rh-python36-python
useradd ansible
su - ansible
source /opt/rh/rh-python36/enable
export PATH=$PATH:$HOME/.local/bin
pip3 install --user ansible
pip3 install --user pywinrm

Windows Configuration

Create a Windows user with password.

$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
# This isn't needed but is a good security practice to complete
Set-ExecutionPolicy -ExecutionPolicy Restricted -Force

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_6_windows.txt · Last modified: 2020/04/29 11:42
Public Domain Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain