つかぱい.com

どうせなら好きなことを書いていたい

OS X High Sierraでansibleをインストールしてみる

Qiitaにも投稿しましたが自分用にも投稿

OS X High Sierraでansibleをインストールしてみる

なんでMacにansibleを入れようと思ったのか?

いつもは仕事でansibleを使っているのですが、自分で管理しているVPSの構成管理をするツールとして便利だろうなとおもったのでインストールしてみたいと思った次第。

最近のroot問題とかセキュリティ周りがLinuxと比べるとガチガチで

/ust/localがパーミッションを弾かれたり、いろいろありましたが

最終的にはpipでインストール出来ました。

以下備忘としての記録

実施環境

OS: 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を使ってインストールを試す

$ 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でインストールするのがベターみたいです。 まあ無駄なこと考えるよりpipでインストールしましょう。

参考にした記事

mac osx に ansible

brew updateをしたらError: /usr/local must be writable!が出た