尋常でないもふもふ

a software engineer blog

Ansibleで変なエラー

事象と原因

brew でインストールした ansible を再インストールしたら動かなくなった。

$ ansible-playbook -i hosts simple-playbook.yml --syntax-check
Traceback (most recent call last):
  File "/usr/local/Cellar/ansible/1.7.2/libexec/bin/ansible-playbook", line 309, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/Cellar/ansible/1.7.2/libexec/bin/ansible-playbook", line 150, in main
    inventory = ansible.inventory.Inventory(options.inventory, vault_password=vault_pass)
TypeError: __init__() got an unexpected keyword argument 'vault_password'

結論から書くと原因は、brew でインストールした ansiblepip でインストールした ansible の競合だった。

解決手順

ansible --version しても 1.7.2 がインストールされてるはずなのに、1.6.2 と表示されてしまう。
同じエラー(unexpected keyword argument 'vault_password')でググってみると Mac 上の ansible ファイルを検索したりしてたので、試しに真似してみた。

$ find / -name "ansible" 2>/dev/null
/Applications/Vagrant/embedded/gems/gems/vagrant-1.6.5/plugins/provisioners/ansible
/Applications/Vagrant/embedded/gems/gems/vagrant-1.6.5/test/unit/plugins/provisioners/ansible
/Users/test/Library/Logs/Homebrew/ansible
/Users/test/Library/Python/2.7/bin/ansible
/Users/test/Library/Python/2.7/lib/python/site-packages/ansible-1.6.1-py2.7.egg/ansible
/Users/test/Library/Python/2.7/lib/python/site-packages/ansible-1.6.1-py2.7.egg/EGG-INFO/scripts/ansible
/Users/test/Library/Python/2.7/lib/python/site-packages/ansible-1.6.2-py2.7.egg/ansible
/Users/test/Library/Python/2.7/lib/python/site-packages/ansible-1.6.2-py2.7.egg/EGG-INFO/scripts/ansible
/usr/local/bin/ansible
/usr/local/Cellar/ansible
/usr/local/Cellar/ansible/1.7.2/bin/ansible
/usr/local/Cellar/ansible/1.7.2/libexec/bin/ansible
/usr/local/Cellar/ansible/1.7.2/libexec/lib/python2.7/site-packages/ansible
/usr/local/Cellar/ansible/1.7.2/share/ansible
/usr/local/lib/python2.7/site-packages/ansible
/usr/local/Library/LinkedKegs/ansible
/usr/local/opt/ansible
/usr/local/share/ansible

/Application/VagrantVagrant 内部のプロビジョナー実装で使われてるものだろうから問題ないと判断した。
/usr/local 配下は brew でインストールしたものだからやはり問題ないが、一応アンインストールして再検索したときに、この一覧からなくなることを確認した。
そこでおかしいのが、/Users/test/Library/Python/2.7 配下の ansible。そういえば遠い昔に easy_install や pip を使った記憶がある。

$ pip --version
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 2793, in <module>
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 673, in require
    def subscribe(self, callback):
  File "build/bdist.macosx-10.8-intel/egg/pkg_resources.py", line 576, in resolve
    plugin_env, full_env=None, installer=None, fallback=True
pkg_resources.DistributionNotFound: pip==1.4.1

pip も使えなくなっていた。Lion → Marverics へのアップグレードでリンクが切れた模様。

$ sudo easy_install --upgrade pip
$ pip list | grep ansible
ansible (1.6.2)
$ pip uninstall ansible
Uninstalling ansible:
  /Users/test/Library/Python/2.7/lib/python/site-packages/ansible-1.6.2-py2.7.egg
Proceed (y/n)? y
  Successfully uninstalled ansible

pip list で ansible がインストールされてることが確認できたため削除。 再度 brew 経由でインストールし、正常に動くようになった。

$ brew install ansible
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/ansible-1.7.2.mavericks.bottle.3.tar.gz
Already downloaded: /Library/Caches/Homebrew/ansible-1.7.2.mavericks.bottle.3.tar.gz
==> Pouring ansible-1.7.2.mavericks.bottle.3.tar.gz
🍺  /usr/local/Cellar/ansible/1.7.2: 1221 files, 15M
$ ansible --version
ansible 1.7.2