Skip to content

Instantly share code, notes, and snippets.

@manualbashing
Last active February 23, 2023 15:02
Show Gist options
  • Save manualbashing/dce01ff8121063435bedc121d179ae19 to your computer and use it in GitHub Desktop.
Save manualbashing/dce01ff8121063435bedc121d179ae19 to your computer and use it in GitHub Desktop.
[Install ansible on Windows Server 2019]

Install WSL

Note: If you are about to configure a vsphere environment, make sure not to use the Debian distribution. The reason is, that the vsphere-module for ansible requires the "vSphere Automation Python SDK", which cannot be installed with pip < 19.1. Unfortunately due to Debian's ultra strict package policies, that version of pip is not yet part of Debian (even in the testing repository).

Invoke-WebRequest -Uri https://aka.ms/wsl-debian-gnulinux -OutFile Debian.zip -UseBasicParsing
Add-AppPackage Debian.zip
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • Reboot system
  • After reboot, initialize the distribution from windows start menu
  • Create a local user account like myuser

image

Enable SSH on WSL

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install openssh-server
sudo nano /etc/ssh/sshd_config

Add the following settings to sshd_config:

Port 2002                    # Port 22 is already taken by "SSH Server Broker Services" on Windows
PasswordAuthentication yes   # Change accordingly, if you are using keys instead
UsePrivilegeSeparation no    # WSL doesn't provide chroot 
PermitRootLogin no           
AllowUsers myuser            # Use the local user, that was created by WSL

Restart the services after saving the changes

sudo service ssh --full-restart

Add a new inbound rule to your local windows firewall, that allows incoming traffic on the port specified above

image

Install python, pip and ansible

sudo apt-get update # If you did not do that before
sudo apt-get -y upgrade
sudo apt-get -y install python-pip python3-pip python-dev libffi-dev libssl-dev
sudo pip install ansible

Prepare for vSphere module

sudo -H pip3 install --upgrade pip
sudo -H pip2 install --upgrade pip
hash -d pip
hash -d pip3
sudo pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git

Connect with your local vscode

Using Remote - SSH Extension

  • Install extension: "Remote - SSH"
  • Click on the icon in the bottom left corner and choose "Remote-SSH: Open Configuration File"

image

  • Choose the configuration file for your current user and add the configuration for your remote host.
Host 10.11.110.11
    HostName 10.11.110.11
    User myuser
    Port 2002
  • Click on the icon in the bottom left corner and choose "Remote-SSH:Connect to Host" and select your host
  • You will be prompted to acknowledge the servers fingerprint and to provide a password (if you are not using ssh keys)

Using Ansible Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment