Cygwin - 如何安装ansible?

13
如何使用Cygwin获取/安装ansible?
我尝试了以下步骤,但在第5步(运行“python setup.py install”时)出现问题。 步骤来自:https://servercheck.in/blog/running-ansible-within-windows 1)下载并安装Cygwin,并至少选择以下软件包(您可以在安装过程中选择软件包):
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) 下载并安装PyYAML和Jinja2,因为它们不会通过Cygwin的安装程序提供:

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>

在第5个步骤中遇到的错误是:

$ 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'

你能把我的答案标记为正确的吗?谢谢。 - zhrist
9个回答

17

简单得多:

#!/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

结果

ansible 2.0.0 (devel 2a50957ad8) last updated 2015/09/15 21:22:17 (GMT -500)

2
找到了:wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg && install apt-cyg /bin。之后,当我运行你的脚本时,它会出现错误:克隆到 'ansible'... 致命错误:无法连接到 github.com: github.com[0: 192.30.252.129]:errno=Connection refused./install_ansible_cygwin.sh: 第5行:cd:ansible:没有那个文件或目录 Traceback (most recent call last): File "/opt/ansible/bin/ansible", line 39, in <module> from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError ImportError: No module named ansible.errors - AKS
我已经成功安装了apt-cyg。但是git克隆失败了。我不得不调整您的脚本,以使其在获取ansible文件夹时正常工作。现在,我正在遇到其他错误。 - AKS
谢谢Steve。我仍然在上面的解决方案中遇到错误。我已经更新了你的答案,不过没关系。 - AKS
有两种方法可以解决这个问题... 1)将你的Cygwin SSH密钥放入Github中,以便使用SSH连接URL。或者2)切换到HTTPS进行下载,链接为:https://github.com/ansible/ansible.git - tplive
@Steven-penny已经接受了,不知道为什么没有标记它。 - AKS

10
假设已经安装了Cygwin:
  • 打开Cygwin终端
  • 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
  • 这里缺少空格并且逗号的存在很重要!
  • 通过pip3 install --upgrade pip升级pip
  • pip install ansible

注:

cyg-get别名允许您通过命令行安装所有软件包,而无需在Cygwin UI中搜索。

ansible安装包括执行“Running setup.py bdist_wheel for pynacl”的步骤-这需要至少半个小时,但最终会完成。


在安装pynacl模块时,我按照其他Python 2的安装说明进行尝试,但是总是遇到gcc致命错误。使用Python 3的这种方法对我很有效。 - Jurgen Strydom

7
尽管Ansible可能可以在Cygwin中使用,但请注意它不受官方支持,并且在不久的将来似乎也不会得到支持。
请注意,从Windows控制机运行Ansible并不是该项目的目标。请勿要求此功能,因为这将限制我们未来可使用的技术、功能和代码。需要一个Linux控制机来管理Windows主机。
Cygwin不受支持,请勿询问有关Ansible在Cygwin上运行的问题。
摘自Ansible文档
考虑的一个替代方案是在您的Windows主机上运行Linux虚拟机,并将其用作您的Ansible控制器。

3

3
  1. 下载Cygwin
  2. 在“选择包”页面上,从视图(左上角)中选择“类别”
  3. 将“开发”标记为“安装”(您将把“默认”更改为“安装”)
  4. 将“Python”标记为“安装”
  5. 从“Web”中选择“wget”
  6. 从“Net”中选择“Openssh”
  7. 继续使用“下一步”安装软件包
  8. 进入安装Cygwin的目标文件夹
  9. 右键单击“Cygwin.bat”并以管理员身份运行
  10. 输入“easy_install-2.7 pip”
  11. 输入“pip2 install ansible”


您还需要重新定位所有软件包以解决分支问题,然后执行以下操作:

  1. rebase-trigger full
  2. 关闭Cygwin shell(或重启Windows)
  3. 再次运行Cygwin安装程序,直到您到达安装结束,然后Cygwin将重新定位所有软件包。

之后您就可以毫无问题地使用ansible了(我希望您和我一样,也能像我一样工作)。

在Windows 10 Home版本上安装ansible花费了我很多天时间去搜索和尝试解决问题。


1
尝试使用apt-get remove python-cryptography命令,同时你可能需要手动安装paramiko-1.10.0.tar.gz。
➤ 运行ansible --version命令,版本为ansible 2.1.0。

1

Ansible 2.7.6、Python3和Cygwin 2.11.2(0.329/5/3)的步骤

  1. 安装Cygwin
  2. 安装Python3
c:\cygwin64-setup>setup-x86_64.exe -q -P python3
$ python3 --version

安装pip。
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py
$ pip --version

安装开发工具(用于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

安装ansible。
$ pip install ansible
$ ansible --version
  1. 检查使用的ssh版本(https://serverfault.com/a/913435)
% which ssh
/cygdrive/c/WINDOWS/System32/OpenSSH/ssh

注意:如果没有使用Cygwin SSH(如上所述),请更改Cygwin的环境PATH变量,或者使用标志ansible_ssh_executable=/usr/bin/ssh更改Ansible清单主机文件项。

嗨,这里花费的时间很长。正在收集pycparser(来自cffi!= 1.11.3,> = 1.8-> 密码学->ansible),为已收集的软件包构建轮子:密码学、pynacl、bcrypt。为密码学构建轮子(PEP 517)... 完成,存储在目录中:/home/r.cardenas.isla/.cache/pip/wheels/43/61/c8/0a4464601ce180d26e0a8dfdfa88c824e419dcc65bd43bda6e。为pynacl构建轮子(PEP 517)... - Robert

0
我遇到了一个“解析符号链接”的问题 - 所以我无法从“pip install /path/absible.tar.gz”安装它。但是我将它解压缩(在根目录下=管理员)到文件夹中,并从文件夹,而不是存档中安装。哦,它可以工作 - ansible已安装到cygwin。

0
这对我有效:
~$ 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接