[PYTHON] Use Ansible on Windows

This article uses ConEmu, MSYS2 and Python2 and Docker Toolbox installed on Windows. Please read the user name as appropriate.

How to use Ansible on Windows

Is it the easiest way to execute the ansible command from a terminal on Windows? I tried and errored aiming for this, but it didn't work. After all, I found that using Docker and Vagrant for each purpose was the easiest. The following is a summary of the results of trial and error. Finally, write down how to reuse Ansible's Role using Docker on Windows.

Try installing Ansible on MSYS2

First of all, I would like to install Ansible as a native windows program. MSYS2 launches the shell with MSYSTEM = mingw64. The installation was done via pip. Python2 and pip used the ones published in the mingw64 repository. On the way, the library may be insufficient when building pycrypto or cryptography. In such a case, if you set CFLAGS, you can correct the include path when compiling gcc.

As a result, I managed to install it. You have generated a Windows native binary. However, when I tried it, I got ʻImportError: No module named fcntl` and it failed.

Then start the shell with MSYSTEM = msys. Python2 and pip used the ones published in the msys repository. However, when I tried it, it became ʻImportError: No module named fcntl` and it failed again.

Try installing Ansible on the command prompt

I installed Python2 from the Windows installer and tried to install Ansible. The Windows compiler that Python2 uses to build is thankfully provided by Microsoft.

And you can install Ansible brilliantly. However, when I tried it, it became ʻImportError: No module named fcntl` and it failed again.

$ /c/Python27/Scripts/ansible --version
Traceback (most recent call last):
  File "C:/Python27/Scripts/ansible", line 45, in <module>
    from ansible.utils.display import Display
  File "C:\python27\lib\site-packages\ansible\utils\display.py", line 21, in <module>
    import fcntl
ImportError: No module named fcntl

After that, I tried using Anaconda2, but it was impossible with the same error.

Use Ansible with Vagrant and VirtualBox

I think there is provisioning as a usage scene of Ansible. Vagrant provides Ansible Provisioner as a provisioning method.

Since Ansible has not been installed on Windows, use Ansible Local. I was able to provision it with Ansible.

Consider reusing Roles and creating Roles

Ansible has an ansible-galaxy command. It is provided for the purpose of reusing Roles, so I would like to create Roles. However, on Windows, Ansible can only be used in the provisioning scene.

Try to reuse Role using Docker

Finally, I will try how to reuse Role using Docker. Use Docker Machine to prepare for using docker commands.

$ docker run --rm -v "//c/Users/<username>/ansible/roles:/etc/ansible/roles" ansible/ansible-container-builder:0.3 ansible-galaxy install geerlingguy.apache

After that, you can use the ansible-galaxy command for Role reuse like the above. Docker usage seems to be the best in scenes other than provisioning.

That's all about how to use Ansible on Windows.

Please teach me in that case because there is a lack of knowledge about MSYS2 and it may be wrong. It's a development on Windows that often stumbles, but I hope it helps someone.

Recommended Posts

Use Ansible on Windows
Use pyvenv on Windows
Use QuTiP on Windows
Use pip on Windows
Use Python on Windows (PyCharm)
Use Linux on Windows 10 (WSL2)
How to use Dataiku on Windows
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Python on Windows
How to use Google Assistant on Windows 10
Use without installing python 2.x on Windows
Use ansible with cygwin
Pylint on Windows Atom
Install Ansible on Mac
Anaconda on Windows Terminal
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Try FEniCS on Windows!
Build XGBoost on Windows
Install pygraphviz on Windows 10
Try Poerty on Windows
Install Chainer 1.5.0 on Windows
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
Preparing to use Ansible on an existing Linux server
Install Numpy on virtualenv on Windows
Set-enable Python virtualenv on Windows
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Use matplotlib on Ubuntu 12 & Python
Install watchdog on Windows + Python 3.3
Install Win-Kex (kali-linux) on Windows 10.
Use music21 on Google Colaboratory
Before trying Veriloggen on Windows
Install cvxpy on windows, Anaconda
Python + Kivy development on Windows
Prepare Chainer environment on Windows
Use Github Desktop on Linux
Try using OpenCV on Windows
F2py on Miniconda for Windows
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Use Windows 10 fonts with WSL
Make Cython available on Windows.
Fastest Python installation on Windows
Operate ubuntu on VScode (windows10)
Build Python environment on Windows
Django environment development on Windows 10
Install Chainer 1.6 (GPU) on Windows 7.
Linux on Windows -1-: debian introduction
Use matplot libwidget on mac
Use sshpass on Amazon linux2
I ran python on windows
[Tensorflow] Tensorflow environment construction on Windows 10
Notes on installing Anaconda 3 on Windows
[Python] [Chainer] [Windows] Install Chainer on Windows
Run Jupyter Notebook on windows
Use NeoPixel on Raspberry Pi
Blogging with Pelican on Windows
How to use VS Code in venv environment on windows