[PYTHON] Putting Ansible in AmazonLinux via yum doesn't work

It seems that the default version of Python is 2.7 in the 2015/03 release of Amazon Linux, which made Ansible via yum a little addictive. Amazon Linux AMI 2015.03 Release Notes

Install Ansible

$ sudo yum install ansible

Dependent packages include python 2.6 series.

==================================================================================================================================================================================================
Package architecture version repository capacity
==================================================================================================================================================================================================
During installation:
 ansible                                                          noarch                            1.9.0.1-2.el6                                   epel                                    1.7 M
Dependency related installation:
 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

Transaction summary
==================================================================================================================================================================================================
Installation 1 package(+18 dependency packages)

Installation confirmation

$ 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

It doesn't work.

$ python --version
Python 2.7.9

The Python version is 2.7 series.

If you change Python to 2.6 series, it will work for the time being

Try changing the Python version to 2.6 series.

$ sudo alternatives --config python

There are 2 programs'python'To provide.

Select command
-----------------------------------------------
*+ 1           /usr/bin/python2.7
   2           /usr/bin/python2.6

Press Enter to select the current[+]Or enter the selection number:2
$ python --version
Python 2.6.9

This works for the time being.

$ 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 doesn't work

However, this doesn't work for yum.

Playbook I tried

---
- hosts:
    - localhost

  connection: local

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

Execution result

$ 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

I don't think it's common to apply a playbook to localhost in Ansible, so it may not be a problem, but it's a bit unpleasant.

Conclusion: Let's install with pip

Let's install Python gently with pip using 2.7 series.

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

This will work. (Warning is out ...)

$ 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

reference

Ansible stopped working after yum update on Amazon Linux

Recommended Posts

Putting Ansible in AmazonLinux via yum doesn't work
Pip doesn't work with PyDev in Pleiades
Tensorflow doesn't work!