The meaning of life is to explore the world

How to install Ansible on WSL

Posted on By Jason Liu

1. Update apt

sudo apt-get update
......
Fetched 7978 kB in 1min 41s (79.3 kB/s)
Reading package lists... Done

2. Install Python etc

sudo apt-get install python-pip git libffi-dev libssl-dev -y
......
W: APT had planned for dpkg to do more than it reported back (330 vs 356).
   Affected packages: libgdbm-compat4:amd64 libgdbm6:amd64 libperl5.28:amd64 perl-base:amd64 perl-modules-5.28:amd64

3. Install Ansible and Pywinrm

pip install ansible pywinrm
......
done
  Stored in directory: /home/jason/.cache/pip/wheels/41/79/b5/1f6f77b8a80eab71e9edd46169ab72940d15dba1e346a64134
......
****  The script chardetect is installed in '/home/jason/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed MarkupSafe-1.1.1 PyYAML-5.3.1 ansible-2.10.3 ansible-base-2.10.3 certifi-2020.11.8 chardet-3.0.4 idna-2.10 jinja2-2.11.2 ntlm-auth-1.5.0 packaging-20.4 pyparsing-2.4.7 pywinrm-0.4.1 requests-2.25.0 requests-ntlm-1.1.0 urllib3-1.26.2 xmltodict-0.12.0 ****

4. Add Ansible to $PATH

ansible --version
Command 'ansible' not found, but can be installed with:
sudo apt install ansible

#  Add Ansible command installation dir to the $PATH
echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc

# Reload bash profile
source .bashrc

5. Verify success

ansible --version
ansible 2.10.3
  config file = None
  configured module search path = [u'/home/jason/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jason/.local/lib/python2.7/site-packages/ansible
  executable location = /home/jason/.local/bin/ansible
  python version = 2.7.17 (default, Sep 30 2020, 13:38:04) [GCC 7.5.0]

Reference link: https://www.jeffgeerling.com/blog/2017/using-ansible-through-windows-10s-subsystem-linux