尝试在 OS X High Sierra 上安装ansible
为什么你想在Mac上安装Ansible?
因为我通常在工作中使用Ansible,但考虑到作为管理我自己的VPS配置的工具可能会很方便,所以我决定尝试安装它。
最近出现了一些与root问题和安全相关的困扰,与Linux相比,这方面可能有些僵硬。像是/usr/local被拒绝权限之类的事情发生了很多,但最终还是通过pip成功安装了。
以下是作为备忘录的记录。
执行环境
操作系统为MacOS HighSierra 10.13
Python版本为2.7.10
Homebrew版本为0.9.9
pip版本为9.0.1
尝试使用HomeBrew进行安装
首先,我想尝试使用我平时常用的HomeBrew来安装,看看是否可行。
$ brew install ansible
目前结果在这边还没有得到很好的支持,导致无法找到部分文件的错误发生。
Warning: You are using OS X 10.13.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
==> Downloading https://releases.ansible.com/ansible/ansible-2.1.0.0.tar.gz
Already downloaded: /Users/pcuser/Library/Caches/Homebrew/ansible-2.1.0.0.tar.gz
<中略>
building '_cffi_backend' extension
creating build/temp.macosx-10.13-intel-2.7
creating build/temp.macosx-10.13-intel-2.7/c
clang -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c/_cffi_backend.c -o build/temp.macosx-10.13-intel-2.7/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
^~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
https://github.com/Homebrew/homebrew-core/issues
Warning: You are using OS X 10.13.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
最近发现我没有进行更新,所以我试图更新,但由于权限问题被阻挡了,无法成功进行。
$ brew update
Error: /usr/local must be writable!
我认为这个区域的设置可能是由于SIP等设置被启用。虽然可以解除权限,但是每次还原都很麻烦,所以稍微改变一下方法。
试试使用pip进行安装
由于HomeBrew无法正常运行,所以我尝试使用pip进行安装。
$ sudo pip install ansible
暂时没有发生错误的状态
The directory '/Users/pcuser/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/pcuser/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting ansible
Downloading ansible-2.4.2.0.tar.gz (6.5MB)
100% |████████████████████████████████| 6.5MB 223kB/s
Requirement already satisfied: jinja2 in /Library/Python/2.7/site-packages (from ansible)
Collecting PyYAML (from ansible)
Downloading PyYAML-3.12.tar.gz (253kB)
100% |████████████████████████████████| 256kB 3.5MB/s
Collecting paramiko (from ansible)
Downloading paramiko-2.4.0-py2.py3-none-any.whl (192kB)
100% |████████████████████████████████| 194kB 4.1MB/s
Collecting cryptography (from ansible)
Downloading cryptography-2.1.4-cp27-cp27m-macosx_10_6_intel.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 868kB/s
Requirement already satisfied: setuptools in /Library/Python/2.7/site-packages (from ansible)
Requirement already satisfied: MarkupSafe>=0.23 in /Library/Python/2.7/site-packages (from jinja2->ansible)
Collecting pyasn1>=0.1.7 (from paramiko->ansible)
Downloading pyasn1-0.4.2-py2.py3-none-any.whl (71kB)
100% |████████████████████████████████| 71kB 6.7MB/s
Collecting bcrypt>=3.1.3 (from paramiko->ansible)
Downloading bcrypt-3.1.4-cp27-cp27m-macosx_10_6_intel.whl (51kB)
100% |████████████████████████████████| 61kB 4.6MB/s
Collecting pynacl>=1.0.1 (from paramiko->ansible)
Downloading PyNaCl-1.2.1-cp27-cp27m-macosx_10_6_intel.whl (243kB)
100% |████████████████████████████████| 245kB 2.3MB/s
Requirement already satisfied: six>=1.4.1 in /Library/Python/2.7/site-packages (from cryptography->ansible)
Collecting cffi>=1.7; platform_python_implementation != "PyPy" (from cryptography->ansible)
Downloading cffi-1.11.2-cp27-cp27m-macosx_10_6_intel.whl (238kB)
100% |████████████████████████████████| 245kB 1.6MB/s
Collecting enum34; python_version < "3" (from cryptography->ansible)
Downloading enum34-1.1.6-py2-none-any.whl
Requirement already satisfied: idna>=2.1 in /Library/Python/2.7/site-packages (from cryptography->ansible)
Collecting asn1crypto>=0.21.0 (from cryptography->ansible)
Downloading asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
100% |████████████████████████████████| 102kB 6.0MB/s
Collecting ipaddress; python_version < "3" (from cryptography->ansible)
Downloading ipaddress-1.0.19.tar.gz
Collecting pycparser (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography->ansible)
Downloading pycparser-2.18.tar.gz (245kB)
100% |████████████████████████████████| 256kB 3.3MB/s
Installing collected packages: PyYAML, pyasn1, pycparser, cffi, bcrypt, enum34, asn1crypto, ipaddress, cryptography, pynacl, paramiko, ansible
Running setup.py install for PyYAML ... done
Running setup.py install for pycparser ... done
Running setup.py install for ipaddress ... done
Running setup.py install for ansible ... done
Successfully installed PyYAML-3.12 ansible-2.4.2.0 asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.2 cryptography-2.1.4 enum34-1.1.6 ipaddress-1.0.19 paramiko-2.4.0 pyasn1-0.4.2 pycparser-2.18 pynacl-1.2.1
结果非常成功地进行了安装。
为了确认一下,我查看了Ansible的版本。
已成功安装了最新的版本。
$ ansible --version
ansible 2.4.2.0
如果要簡單安裝,建議使用pip來進行安裝,因為它少有錯誤。
参考的文章
当我在Mac OSX上使用Ansible进行brew更新时,遇到了错误信息:“Error: /usr/local must be writable!”