Ansible and WSL

Ansible and WSL

2021, Jan 25    

Getting Ansible 2.9 working in my Ubuntu 18.04 has been a bit of a pain, seemingly no matter what i did i couldn’t get it installed without it using Python2 instead of Python3. This in turn causes issues with the dependant python3 scripts used by the the Azure python module.

After a few attempts, the only real solution i found was to run a newer version of Ubuntu in WSL. I had been using 18.04, but 20.04 seems like it was having more success for others - likely in part because of the way the Ansible repo shows up between the two versions of Ubuntu.

WSL

Start by backing up your Ubuntu WSL with

wsl.exe --export Ubuntu C:\ubuntu-1804-backup.tar.gz

It takes a few minutes and results in a large file (about 12GB for me), but it worth doing in case you need to rollback.

Upgrading Ubuntu?

Ok, so you can try and upgrade your instance by following this guide, but i’d suggest that it’s high time to go fresh.

I don’t leverage any storage inside my Ubuntu WSL, instead using mount points for Azure Files and the local windows host. Therefore it’s pretty easy to go fresh.

If you really want to try and upgrade, here’s the best guide; https://discourse.ubuntu.com/t/installing-ubuntu-20-10-on-wsl/18941

Getting Ansible 2.9 working in Ubuntu 20.04

You don’t need to reference any other repos, simply install with;

sudo apt install ansible
admingeneric@DESKTOP-NTJ7TEA:/mnt/cloudshell/Ansible$ ansible all -m ping -i ./myazure_rm.yml
[WARNING]:  * Failed to parse /mnt/cloudshell/Ansible/myazure_rm.yml with script plugin: problem running
/mnt/cloudshell/Ansible/myazure_rm.yml --list ([Errno 8] Exec format error: '/mnt/cloudshell/Ansible/myazure_rm.yml')
[WARNING]:  * Failed to parse /mnt/cloudshell/Ansible/myazure_rm.yml with auto plugin: No module named 'msrest'
[WARNING]:  * Failed to parse /mnt/cloudshell/Ansible/myazure_rm.yml with yaml plugin: Plugin configuration YAML file,
not YAML inventory
[WARNING]:  * Failed to parse /mnt/cloudshell/Ansible/myazure_rm.yml with ini plugin: Invalid host pattern 'plugin:'
supplied, ending in ':' is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /mnt/cloudshell/Ansible/myazure_rm.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'

The problem here is that my local environment, although has ansible installed, does not have all the requirements for talking to Azure. We can grab them from [https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt] (https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt)

wget https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt
pip3 -r requirements-azure.txt

A successful connection

admingeneric@DESKTOP-NTJ7TEA:/mnt/cloudshell/Ansible$ ansible all -m ping -i ./myazure_rm.yml
The authenticity of host '13.90.73.18 (13.90.73.18)' can't be established.
ECDSA key fingerprint is SHA256:+nF0hQ++lMqRAYwzVsj4xk6GFhEXB2TGrIzoGQpUhOA.
The authenticity of host '104.211.54.81 (104.211.54.81)' can't be established.
ECDSA key fingerprint is SHA256:Im/VCFkAOBDG+PbFMv/hzlbCqbNGDveppAN09B1E8BE.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

My Ansible version;

admingeneric@DESKTOP-NTJ7TEA:/mnt/cloudshell/Ansible$ ansible --version
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/admingeneric/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]