How to run Ansible on Windows?
Tags: devops, ansible, tutorial, automation
Published: 2024-06-12 10:54:54

![We’re trying to make DevOps simple-stupid](https://cdn-images-1.medium.com/max/2000/1*kvRaNtWaLG6GBDW8lQNdeQ.png)

If you need consistant way to run Ansible on Mac, Linux and Windows you'll face a surprise! Ansible is not supported on Windows - https://docs.ansible.com/ansible/latest/os_guide/windows_faq.html#can-ansible-run-on-windows

Sad, right? But if you're doing tool like DevOps Pass, you need it.

So I was inspired by OpenTofu's tenv and created my own Ansible Version Manager, which allows you to run Ansible from Windows host, like on Mac or Linux.

## Whats behind?

It uses Docker under the hood and allowing you to run Ansible tools from your local without installation of Python (on Mac/Linux) and on Windows.

It is running Docker container, pushing all your local environment variables related to Ansible, Molecule, SSH, AWS, Azure and GCP configuration.

## 🚀 Installation

### MacOS / Linux

```bash
# Linux
curl -sL $(curl -s https://api.github.com/repos/devopspass/dop-avm/releases/latest | grep "https.*linux_amd64" | awk '{print $2}' | sed 's/"//g') | tar xzvf - dop-avm
# MacOS
curl -sL $(curl -s https://api.github.com/repos/devopspass/dop-avm/releases/latest | grep "https.*darwin_amd64" | awk '{print $2}' | sed 's/"//g') | tar xzvf - dop-avm

sudo mv dop-avm /usr/local/bin/
sudo sh -c "cd /usr/local/bin/ && dop-avm setup"
```

### Windows

Download latest binary for Windows - https://github.com/devopspass/dop-avm/releases/

```cmd
tar xzf dop-avm*.tar.gz
md %USERPROFILE%\bin
move dop-avm.exe %USERPROFILE%\bin\
setx PATH "%USERPROFILE%\bin;%PATH%"

cd %USERPROFILE%\bin\
dop-avm setup
```

### DevOps Pass AI

In DOP you can add **Ansible** app and run action **Install Ansible Version Manager**, it will download and install `dop-avm`.

![Ansible Version manager install](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncpbgrgoq38t5s2z17vl.png)

## 🤔 How it works?

`dop-avm` copying own binary with different names, which will be used later by user:

* ansible
* ansible-playbook
* ansible-galaxy
* ansible-vault
* ansible-doc
* ansible-config
* ansible-console
* ansible-inventory
* ansible-adhoc
* ansible-lint
* molecule

When you're running any of this command, it will run Docker container `devopspass/ansible:latest` and binary inside (source Dockerfile in repo).

AVM will pass environment variables from host machine:

* `ANSIBLE_*`
* `MOLECULE_*`
* `GALAXY_*`
* `AWS_*`
* `GOOGLE_APPLICATION_CREDENTIALS`

Plus volumes (if exist):

* `.ssh`
* `.aws`
* `.azure`
* `.ansible`

And services, like SSH-agent and Docker socket.
As a result you can run Ansible on Windows, MacOS and Linux via Docker without installation of Python and Ansible on your local, especially it's useful for Windows where it's not possible to run Ansible at all.

## 🐳 Use another Docker container

Probably you may have Docker container built in your organization, which is used in pipelines or recommended for local, you can use it by specifying `DOP_AVM_IMAGE_NAME` environment variable. Be sure that all necessary binaries, like `molecule` are inside, when you're running it.

## Support Us, Contact Us

![Give us a start, we’re kitties ;)](https://cdn-images-1.medium.com/max/2592/0*6cJukGznvBKbMYi8.jpeg)

If you like this post, support us, download, try and give us feedback!

Give us a star 🌟 on [GitHub](https://github.com/devopspass/devopspass/) or join our community on [Slack](https://join.slack.com/t/devops-pass-ai/shared_invite/zt-2gyn62v9f-5ORKktUINe43qJx7HtKFcw).