Preparing for Ansible
Credentials
You need to obtain some information from the Immersive Labs Ranges dashboard so Ansible can communicate with each host and configure them.
For Linux hosts, this can be done using the range SSH private key, found in the Settings menu:
Windows hosts are deployed with a set password which can be obtained from the Credentials tab for each individual machine:
The password for marketplace server AMIs is the RID500 Administrator account password. These credentials must be hard-coded into the [relevant Ansible inventory file, here](../blob/main/range/inventory.yml). The variable `ansible_password` should be modified for each host.
WinRM restrictions
Windows AMIs from the AWS marketplace are deployed with WinRM enabled by default. But they use the default configuration, which restricts access to only allow hosts within the same subnet to successfully connect to the service. Each Windows machine needs to be accessed via Guacamole RDP, and the following commands run in a `PowerShell.exe` console:
```PowerShell
echo y | winrm quickconfig
Enable-WSManCredSSP -Role Server -Force
Set-NetFirewallRule -DisplayName "Windows Remote Management (HTTP-In)" -RemoteAddress Internet
```
Install dependencies on Temp-Ansible
To manage a Windows machine using Ansible, it's necessary to install Ansible and the required dependencies on the Temp-Ansible host. This part will walk you through the process using Python3 and `pip`.
Preparing your system
Before installing Ansible, make sure Python3 and `pip` are installed on your Temp-Ansible host.
[!NOTE]
On the Ubuntu Server 22.04 instance, Python3 is already installed.
1. Update package lists:
```bash
sudo apt update
```
2. Install Python3 (if not already installed):
```bash
sudo apt install python3
```
3. Install `pip`:
```bash
sudo apt install python3-pip -y
```
Installing Ansible and required dependencies
With Python3 and `pip` installed, you can now install Ansible and the required dependencies.
1. Install Ansible:
```bash
python3 -m pip install --user ansible
```
2. Install Python libraries for Windows Management – install `pywinrm` for Windows Remote Management and `requests-credssp` for CredSSP authentication:
```bash
python3 -m pip install --user pywinrm requests-credssp
```
Once the installation is complete, you can verify it by running the following command after rebooting the Temp-Ansible host:
ansible --version
Installing Ansible packages for supporting Windows hosts
Further Ansible collections are required to support Windows hosts – mostly for supporting Ansible Windows modules, as you're building an Active Directory domain. The following Ansible Galaxy collections are required and can be installed by running the following commands respectively. However, these roles are already installed on the Temp-Ansible host if you've followed the steps mentioned above.
```bash
ansible-galaxy collection install ansible.windows
ansible-galaxy collection install community.windows
ansible-galaxy collection install chocolatey.chocolatey
```
To verify if these packages have already been installed, or have been installed correctly, run the following command:
```bash
ansible-galaxy collection list ansible.windows
ansible-galaxy collection list community.windows
ansible-galaxy collection list chocolatey.chocolatey
```