13

How to get / install ansible using Cygwin?

I tried the following steps but it's didn't work during bullet 5 (while running "python setup.py install"). Steps taken from: Taken from https://servercheck.in/blog/running-ansible-within-windows

1) Download and install Cygwin, with at least the following packages selected (you can select the packages during the install process):

libyaml
libyaml-devel
curl
python (2.7.x)
python-crypto
python-openssl
python-paramiko
python-setuptools
git (2.1.x)
vim
openssh
openssl
openssl-devel

2) Download and install PyYAML and Jinja2, as they're not available via Cygwin's installer:

1. Open Cygwin
2. Download PyYAML:
    curl -O https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.10.tar.gz
3. Download Jinja2:
    curl -O https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.6.tar.gz
4. Untar both downloads:
    tar -xvf PyYAML-3.10.tar.gz && tar -xvf Jinja2-2.6.tar.gz
5. Change directory into each of the expanded folders and run python "python setup.py install" to install each package.
6. Clone ansible from its repository on GitHub:
    git clone https://github.com/ansible/ansible /opt/ansible
    This was tested with Ansible version v1.6.6, change directory into /opt/ansible and checkout the correct tag: git checkout v1.6.6.
7. Add the following lines into your Cygwin .bash_profile:
    # Ansible settings
    ANSIBLE=/opt/ansible
    export PATH=$PATH:$ANSIBLE/bin
    export PYTHONPATH=$ANSIBLE/lib
    export ANSIBLE_LIBRARY=$ANSIBLE/library

8. At this point, you should be able to run ansible commands via Cygwin (once you restart, or enter source ~/.bash_profile to pick up the settings you just added). 
    Try ansible --version to display Ansible's version.

9. Passwordless ssh will need to be set up between your Windows machine and the deployment host(s)
    To enable passwordless ssh on Centos -  ssh-copy-id root@node
    To enable passwordless ssh on SuSE I followed the steps in this blog:
    http://www.firedaemon.com/blog/passwordless-root-ssh-public-key-authentication-on-centos-6
    install sshpass v1.05 on your Windows machine<br>

The error that I got during during bullet 5 is:

$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib.cygwin-2.2.1-x86_64-2.7
creating build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/composer.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/constructor.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/cyaml.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/dumper.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/emitter.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/error.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/events.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/loader.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/nodes.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/parser.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/reader.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/representer.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/resolver.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/scanner.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/serializer.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/tokens.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
copying lib/yaml/__init__.py -> build/lib.cygwin-2.2.1-x86_64-2.7/yaml
running build_ext
creating build/temp.cygwin-2.2.1-x86_64-2.7
checking if libyaml is compilable
gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/build=/usr/src/debug/python-2.7.10-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/src/Python-2.7.10=/usr/src/debug/python-2.7.10-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/cygdrive/c/cygwin/include/python2.7 -c build/temp.cygwin-2.2.1-x86_64-2.7/check_libyaml.c -o build/temp.cygwin-2.2.1-x86_64-2.7/check_libyaml.o
checking if libyaml is linkable
gcc build/temp.cygwin-2.2.1-x86_64-2.7/check_libyaml.o -L/cygdrive/c/cygwin/lib/python2.7/config -L/usr/lib -lyaml -o build/temp.cygwin-2.2.1-x86_64-2.7/check_libyaml.exe
skipping 'ext/_yaml.c' Cython extension (up-to-date)
building '_yaml' extension
creating build/temp.cygwin-2.2.1-x86_64-2.7/ext
gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/build=/usr/src/debug/python-2.7.10-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.10-1.x86_64/src/Python-2.7.10=/usr/src/debug/python-2.7.10-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/cygdrive/c/cygwin/include/python2.7 -c ext/_yaml.c -o build/temp.cygwin-2.2.1-x86_64-2.7/ext/_yaml.o
ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

.

$ ansible --version
Traceback (most recent call last):
  File "/opt/ansible/bin/ansible", line 40, in <module>
    from ansible.utils.display import Display
  File "/opt/ansible/lib/ansible/utils/display.py", line 35, in <module>
    from ansible import constants as C
  File "/opt/ansible/lib/ansible/constants.py", line 30, in <module>
    from ansible.parsing.splitter import unquote
  File "/opt/ansible/lib/ansible/parsing/__init__.py", line 32, in <module>
    from ansible.parsing.vault import VaultLib
  File "/opt/ansible/lib/ansible/parsing/vault/__init__.py", line 82, in <module>
    from cryptography.hazmat.primitives.hashes import SHA256 as c_SHA256
  File "/cygdrive/c/cygwin/lib/python2.7/site-packages/cryptography/hazmat/primitives/hashes.py", line 15, in <module>
    from cryptography.hazmat.backends.interfaces import HashBackend
  File "/cygdrive/c/cygwin/lib/python2.7/site-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
    import pkg_resources
  File "/cygdrive/c/cygwin/lib/python2.7/site-packages/pkg_resources/__init__.py", line 84, in <module>
    packaging = pkg_resources._vendor.packaging
AttributeError: 'module' object has no attribute '_vendor'
AKS
  • 16,482
  • 43
  • 166
  • 258

9 Answers9

17

Much easier:

#!/bin/sh
type apt-cyg || exit
apt-cyg install git python-{jinja2,six,yaml}
git clone --depth 1 git://github.com/ansible/ansible
cd ansible
PATH+=:~+/bin
export PYTHONPATH=~+/lib
ansible --version

Result

ansible 2.0.0 (devel 2a50957ad8) last updated 2015/09/15 21:22:17 (GMT -500)
Zombo
  • 1
  • 62
  • 391
  • 407
  • 2
    Found it: wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg && install apt-cyg /bin. After this when I run your script, it errors out with this: Cloning into 'ansible'... fatal: unable to connect to github.com: github.com[0: 192.30.252.129]: errno=Connection refused ./install_ansible_cygwin.sh: line 5: cd: ansible: No such file or directory Traceback (most recent call last): File "/opt/ansible/bin/ansible", line 39, in from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError ImportError: No module named ansible.errors – AKS Sep 17 '15 at 01:09
  • I got apt-cyg installed successfully. git clone failed. I had to tweak your script to get it working upto the point to get ansible folder. Now, I'm getting other errors. – AKS Sep 17 '15 at 01:34
  • Thanks Steve. I still have errors with the solution above. Updated your answer but never mind. – AKS Sep 17 '15 at 21:43
  • Two ways past this... 1) put your cygwin ssh key into Github in order to use the SSH connection URL. Or 2) Switch to HTTPS for this download, the link is then: https://github.com/ansible/ansible.git – tplive Feb 19 '19 at 13:14
  • @Steven-penny accepted, somehow missed to mark it – AKS Mar 15 '21 at 17:54
10

Assuming Cygwin is installed:

  • Open up a Cygwin Terminal
  • alias cyg-get="/path/to/cygwin/setup/package/setup-x86_64.exe -q -P"
  • cyg-get cygwin32-gcc-g++,gcc-core,gcc-g++,git,libffi-devel,nano,openssl,openssl-devel,python-crypto,python3,python3-devel,python3-openssl,python3-pip,python3-setuptools,python3-devel,tree,wget,zip,make
  • The lack of spaces and the presence of commas here is important!
  • Upgrade pip via pip3 install --upgrade pip
  • pip install ansible

Notes:

The cyg-get alias allows you to install all packages via the command line instead of searching in the Cygwin UI.

The ansible installation includes a step where "Running setup.py bdist_wheel for pynacl" is executed - this takes at least half an hour but does eventually complete.

Bonnie
  • 101
  • 1
  • 4
  • With other python 2 installation instructions I kept getting a fatal error with gcc when installing the pynacl module, this method with python 3 worked for me. – Jurgen Strydom Jul 29 '18 at 15:44
7

Although Ansible may work in Cygwin, note that it is not officially supported and it doesn't sound like it will be in the near future.

Note running Ansible from a Windows control machine is NOT a goal of the project. Refrain from asking for this feature, as it limits what technologies, features, and code we can use in the main project in the future. A Linux control machine will be required to manage Windows hosts.

Cygwin is not supported, so please do not ask questions about Ansible running from Cygwin.

Taken from the Ansible Documentation

One alternative to consider is running a Linux virtual machine on your Windows host and use that as your Ansible controller.

Community
  • 1
  • 1
Steve E.
  • 9,003
  • 6
  • 39
  • 57
3


    1. download cygwin
    2. on the "Select Packages" page, select "Category" from the View (on top left)
    3. mark "Devel" to "Install" (you will change the "Default" to "Install"
    4. mark "Python" to "Install"
    5. from "Web" select "wget"
    6. from "Net" select "Openssh"
    7. progress to install the packages with "Next"
    8. go to the destination folder where you installed cygwin
    9. right click "Cygwin.bat" and run as Administrator
    10. write "easy_install-2.7 pip"
    11. write "pip2 install ansible"


You need also to rebase all the packages to solve the problem of forking, for this then write:

  1. rebase-trigger full
  2. close Cygwin shells (or even reboot your windows)
  3. run Cygwin installer again and just click on "Next" until you reach the end of the installation, then Cygwin will rebase all the packages.

After that you can use ansible without any problem (I hope so you will have the same situation as me, as it's working for me)

It took me a lot of days searching and trying to solve installing ansible on Windows 10 Home Edtion

Arkan
  • 579
  • 1
  • 6
  • 20
3

With later installer https://cygwin.com/setup-x86_64.exe you can install ansible and ansible-doc directly. Just select it from the list and set to install.

zhrist
  • 1,169
  • 11
  • 28
1

Try this apt-get remove python-cryptography, also you may need to install paramiko-1.10.0.tar.gz manually.

➤ ansible --version ansible 2.1.0

Deepak Tom
  • 11
  • 1
1

Steps for Ansible 2.7.6 and Python3 and Cygwin 2.11.2(0.329/5/3)

  1. Having Cygwin installed
  2. Install python3
c:\cygwin64-setup>setup-x86_64.exe -q -P python3
$ python3 --version
  1. Install pip
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py
$ pip --version
  1. Install dev tools (for Ansible)
c:\cygwin64-setup>setup-x86_64.exe -q -P make
c:\cygwin64-setup>setup-x86_64.exe -q -P gcc-g++
c:\cygwin64-setup>setup-x86_64.exe -q -P python3-devel
c:\cygwin64-setup>setup-x86_64.exe -q -P libffi-devel
c:\cygwin64-setup>setup-x86_64.exe -q -P openssl-devel
c:\cygwin64-setup>setup-x86_64.exe -q -P openssh
  1. Install ansible
$ pip install ansible
$ ansible --version
  1. Check which ssh is used (https://serverfault.com/a/913435)
% which ssh
/cygdrive/c/WINDOWS/System32/OpenSSH/ssh

Note: if not cygwin ssh is used (like above) change env PATH variable for cygwin or change Ansible inventory hosts file items with flag ansible_ssh_executable=/usr/bin/ssh

bedla.czech
  • 879
  • 1
  • 8
  • 13
  • hi it is taking long time here ```Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography->ansible) Building wheels for collected packages: cryptography, pynacl, bcrypt Building wheel for cryptography (PEP 517) ... done Stored in directory: /home/r.cardenas.isla/.cache/pip/wheels/43/61/c8/0a4464601ce180d26e0a8dfdfa88c824e419dcc65bd43bda6e Building wheel for pynacl (PEP 517) ...``` – Robert Mar 15 '19 at 18:58
0

I had a problem with "resolve symbolic links" - so i coudn't install it from "pip install /path/absible.tar.gz" But i unpacked it (under root = administrator) to folder and installed from folder, not archive. And - oh, it works - ansible was installed to cygwin.

0

This worked for me:

~$ cat setup_ansible_cygwin.sh

#!/bin/sh

echo binutils,curl,gcc-g++,git,gmp,libffi-devel,libgmp-devel,\
make,nano,openssh,openssl-devel,python-crypto,python-paramiko, \
python2,python2-devel,python2-openssl,python2-pip,python2-setuptools |\
        tr ',' ' ' |\
        xargs apt-cyg install

apt-cyg remove python2
apt-cyg install python2

pip2 install --upgrade pip
pip2 install ansible
# inside: Installing collected packages: MarkupSafe, jinja2, PyYAML, ansible
tejot7
  • 1