Configure Ansible To Use WinRM
To configure Ansible to connect to Windows Servers from a Red Hat Enterprise Linux 8 server, you need to install the following prerequisites:
- Install the
pywinrm
module:
pip3 install pywinrm
- Install the
xmltodict
module:
pip3 install xmltodict
-
Enable WinRM on the Windows Server and configure the firewall to allow incoming connections on the WinRM port (5985 for HTTP, 5986 for HTTPS).
-
Create a user account on the Windows Server with administrative privileges.
Once you have completed these prerequisites, you can configure Ansible to connect to the Windows Servers by adding the following to your ansible.cfg
file:
[defaults]
inventory = /path/to/inventory.yml
remote_user = username
ansible_connection = winrm
ansible_winrm_server_cert_validation = ignore
Where /path/to/inventory.yml
is the path to your inventory file containing the list of Windows Servers to manage, username
is the name of the user account you created on the Windows Servers, and ansible_winrm_server_cert_validation
is set to ignore
to bypass certificate validation.
You can also specify the connection details for individual hosts in the inventory file using the following format:
[windows_servers]
windows_server_hostname ansible_host=ip_address ansible_user=username ansible_password=password
Where windows_server_hostname
is the name of the Windows Server, ip_address
is the IP address of the Windows Server, username
is the name of the user account you created on the Windows Server, and password
is the password for the user account.
Once you have configured Ansible to connect to the Windows Servers, you can use the win_command
, win_shell
, and other Windows-specific Ansible modules to manage the servers.