14

Having trouble running Ansible on the latest version of amazon linux.

[root@ip-10-0-0-11 ec2-user]# yum install ansible --enablerepo=epel
[root@ip-10-0-0-11 ec2-user]# ansible-playbook
Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 44, in <module>
    import ansible.playbook
ImportError: No module named ansible.playbook

Using AMI ID: ami-a10897d6.

Any ideas?

8 Answers 8

31

It appears that python library files do not have correct permissions by default. Running this fixed it for me.

[root@ip-10-0-0-11 ansible]# pip install ansible
5

Using pip (alone, not in conjunction with yum) is probably the best option right now on Amazon Linux. I'd suggest getting rid of the yum-installed copy if it's still there.

The RPM specs in epel and epel-testing (as of 1.9.2) currently handle only RHEL, Fedora, and SuSE, and the defaults are installing everything under Python 2.6, where the latest Amazon Linux has default Python 2.7. A bit of work will be required to get the RPM install working under Amazon Linux...

2
  • Which means typing in # pip install ansible May 22, 2017 at 18:49
  • But pip is not installed Amazon linux by default.
    – Brian
    Sep 6, 2019 at 9:05
5

For Amazon Linux2 AMI:

sudo yum update
sudo yum install ansible

or

sudo amazon-linux-extras install ansible2

For Amazon Linux AMI:

sudo yum update
sudo yum install ansible --enablerepo=epel

For Ubuntu 18.04 AMI:

sudo apt-get update
sudo apt-get install ansible

Note: You can install ansible using "pip".

sudo yum install python-pip
sudo pip install ansible
3

Why not check out the source code from git and and checkout the latest stable version.

git clone git://github.com/ansible/ansible.git --recursive
$ cd ./ansible
$ source ./hacking/env-setup
git checkout <VERSION>
2

Just enable the below repo from the /etc/yum.repos.d/redhat-rhui.repo file by default is disabled.

rhui-REGION-rhel-server-extras/7Server/x86_64

3
  • Please add some description to your answer. Dec 21, 2017 at 13:41
  • As we can create a new instance in AWS with Redhat 7.4 by default ansible repo i.e "rhui-REGION-rhel-server-extras/7Server/x86_64" will be disabled, so we need to enable this repo. later on you can try this should be comes in the output of command #yum repolist
    – M.Rajput
    Dec 27, 2017 at 5:55
  • The commands I used: vi /etc/yum.repos.d/redhat-rhui.repo # find entry titled [rhui-rhel-7-server-rhui-extras-rpms] # change "enabled=0" to "enabled=1" # save and quit file ":wq" sudo yum install ansible
    – schmudu
    Jun 3, 2020 at 14:51
2

This article says that you can use sudo amazon-linux-extras install ansible2 to install ansible on Amazon linux.

1

On Amazon Linux 2 to get the latest version of Ansible do not use yum (currently it won't give you 2.10.x), I recommend you use python3-pip.

sudo yum remove ansible
sudo yum install -y python3-pip
python3 -m pip install --user --upgrade pip # Do not run pip as sudo. Do this instead.
python3 -m pip install ansible

If you don't already have python3 you may need this step before the above:

sudo yum install -y python3.7

In my case, I needed ansible 2.10.x because it has the added benefit of requirements.yml files being able to install collections directly from git repositories.

0

This answer is based off of @M.Rajput's answer. I wanted to define the details so I wouldn't forget.

Warning: this was only tested on a RHEL 7.7 Community AMI (ami-029c0fbe456d58bd1).

# modify yum repo enabled
sudo vi /etc/yum.repos.d/redhat-rhui.repo

# find entry titled [rhui-rhel-7-server-rhui-extras-rpms]
# change "enabled=0" to "enabled=1"
# save and quit file (vim command is :wq)
sudo yum install ansible

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.