LoginSignup
27
25

More than 5 years have passed since last update.

AmazonLinux に yum 経由で Ansible を入れても動かない

Last updated at Posted at 2015-05-24

2015/03 リリースの Amazon Linux で Python のデフォルトバージョンが 2.7 になったらしく、そのせいで yum 経由の Ansible が動かなくてちょっとハマった。
Amazon Linux AMI 2015.03 Release Notes

Ansible をインストール

$ sudo yum install ansible

依存パッケージに python 2.6 系が含まれてる。

==================================================================================================================================================================================================
 Package                                                          アーキテクチャー                  バージョン                                      リポジトリー                             容量
==================================================================================================================================================================================================
インストール中:
 ansible                                                          noarch                            1.9.0.1-2.el6                                   epel                                    1.7 M
依存性関連でのインストールをします:
 python-crypto2.6                                                 x86_64                            2.6.1-2.el6                                     epel                                    513 k
 python-keyczar                                                   noarch                            0.71c-1.el6                                     epel                                    219 k
 python26                                                         x86_64                            2.6.9-1.80.amzn1                                amzn-updates                            5.7 M
 python26-PyYAML                                                  x86_64                            3.10-3.10.amzn1                                 amzn-main                               186 k
 python26-babel                                                   noarch                            0.9.4-5.1.8.amzn1                               amzn-main                               1.8 M
 python26-backports                                               x86_64                            1.0-3.14.amzn1                                  amzn-main                               5.2 k
 python26-backports-ssl_match_hostname                            noarch                            3.4.0.2-1.12.amzn1                              amzn-main                                12 k
 python26-crypto                                                  x86_64                            2.6.1-1.10.amzn1                                amzn-main                               697 k
 python26-ecdsa                                                   noarch                            0.11-3.3.amzn1                                  amzn-main                                77 k
 python26-httplib2                                                noarch                            0.7.7-1.5.amzn1                                 amzn-main                                81 k
 python26-jinja2                                                  noarch                            2.7.2-2.15.amzn1                                amzn-main                               899 k
 python26-libs                                                    x86_64                            2.6.9-1.80.amzn1                                amzn-updates                            692 k
 python26-markupsafe                                              x86_64                            0.11-4.6.amzn1                                  amzn-main                                27 k
 python26-paramiko                                                noarch                            1.15.1-1.5.amzn1                                amzn-main                               1.3 M
 python26-pyasn1                                                  noarch                            0.1.7-2.7.amzn1                                 amzn-main                               174 k
 python26-setuptools                                              noarch                            12.2-1.30.amzn1                                 amzn-updates                            582 k
 python26-simplejson                                              x86_64                            3.6.5-1.12.amzn1                                amzn-main                               210 k
 python26-six                                                     noarch                            1.8.0-1.23.amzn1                                amzn-main                                31 k

トランザクションの要約
==================================================================================================================================================================================================
インストール  1 パッケージ (+18 個の依存関係のパッケージ)

インストール確認

$ ansible localhost --connection=local -m ping
Traceback (most recent call last):
  File "/usr/bin/ansible", line 36, in <module>
    from ansible.runner import Runner
ImportError: No module named ansible.runner

動かない。

$ python --version
Python 2.7.9

Python のバージョンは 2.7 系になっている。

Python を 2.6 系にすれば一応動く

Python のバージョンを 2.6 系にしてみる。

$ sudo alternatives --config python

2 プログラムがあり 'python' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/bin/python2.7
   2           /usr/bin/python2.6

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:2
$ python --version
Python 2.6.9

これで一応動く。

$ ansible localhost --connection=local -m ping
 [WARNING]: The version of gmp you have installed has a known issue regarding
timing vulnerabilities when used with pycrypto. If possible, you should update
it (i.e. yum update gmp).

localhost | success >> {
    "changed": false,
    "ping": "pong"
}

yum が動かない

ただ、これだと yum が動かなくなる。

試してみた Playbook

---
- hosts:
    - localhost

  connection: local

  tasks:
    - name: update all packages
      yum: name=* state=latest
      sudo: yes

実行結果

$ ansible-playbook test.yml
 [WARNING]: The version of gmp you have installed has a known issue regarding
timing vulnerabilities when used with pycrypto. If possible, you should update
it (i.e. yum update gmp).


PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [update all packages] ***************************************************
failed: [localhost] => {"failed": true, "parsed": false}
BECOME-SUCCESS-cowfsuudxofapfzgotceycqgfeksicos
Traceback (most recent call last):
  File "/home/ec2-user/.ansible/tmp/ansible-tmp-1430645872.15-203675717416361/yum", line 27, in <module>
    import yum
ImportError: No module named yum


FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/ec2-user/test.retry

localhost                  : ok=1    changed=0    unreachable=0    failed=1

Ansible で localhost に Playbook を適用することはそう多くないと思うので問題になることはそんなに多くないのかもしれませんがちょっと気持ち悪いですね。

結論: pip でインストールしましょう

Python はおとなしく 2.7 系を使って pip でインストールしましょう。

$ python --version
Python 2.7.9
$ sudo pip install ansible
...
Successfully installed ansible-1.9.1

これなら動く。(Warning 出てるけど…)

$ ansible-playbook test.yml
/usr/lib64/python2.7/dist-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
  _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [update all packages] ***************************************************
changed: [localhost]

PLAY RECAP ********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

参考

Amazon Linux で yum update したら Ansible が動かなくなった

27
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
25