How to install ansible on amazon aws? - ansible

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?

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

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...

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

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>

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

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

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.

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

Related

System does not update Ansible on CentOS 8

I try to install ansible-core, which version is 2.12. I am installing this as per the documentation.
$ yum install epel-release
$ yum install ansible
But, the system keeps installing version 2.9.27.
It really makes me annoying because I've already had experience of installing ansible-core before and it worked. Anyway, I tried to reinstall ansible on the other CentOS 8 servers with the same installation process as I did before.
Please let me know how to install latest version or specific version of Ansible.
You can check the newest version of packages on this site: https://pkgs.org/search/?q=ansible.
At this point, the newest ansible package version is 2.9.27. So, you need to wait until they release a new version or consider compiling this package from the source yourself.
try
sudo yum install ansible-2.12.1
as in
sudo yum install <package_name>-<version_info>
hope this will work
But, the system keeps installing version 2.9.27.
You're installing Ansible from a repository. This means someone has packaged a certain version of Ansible.
You're OS is EL 8-like, the note on the website describes:
Since Ansible 2.10 for RHEL is not available at this time, continue to use Ansible 2.9.
how to install latest version or specific version of ansible
When installing python packages, you should not use the package manager of the system, but rather Pip. So, as part of the answer which is already been given in the comments, you should install Ansible via pip.
$ dnf install epel-release -y ; dnf install python3-pip -y
$ python3 -m pip install ansible
You can update to the latest version with:
$ python3 -m pip install ansible --upgrade
Install a specific version with:
$ python3 -m pip install ansible==5.0.1
Ensure to install python modules the same way you install Ansible.
$ python3 -m pip install yamllint

How do I install pip modules on google compute engine?

I am trying to run some python script using ssh to log into the google compute engine but all the installed pip modules are not found as I do not have permission to the .cache/pip folder in my user is there a correct way to do this?
You should be running this with the root user.
Also, if you need pip inside your GCP Instance, you can use the following commands:
sudo curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
sudo python get-pip.py
[Source]
Use:
sudo apt-get install python3-pip
sudo runs this command as an administrator
apt-get is the standard package manager used on Debian Linux distributions
python3-pip is the package name for pip3
Once installed, you can install PIP modules with:
pip3 install MODULE_NAME
for example:
pip3 install tensorflow
I'm not entirely sure there is one correct way to do this, but an easy way would be to use the conda python package manager.
The lighter version of it is miniconda. You can get a minimal python installation with pip preinstalled, and virtual environments capability if you need. Assuming you are running on linux and want python 3, you'll have to run
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
and then install conda with
bash Miniconda3-latest-Linux-x86_64.sh
At the end of this process you should have a minimal python installation (that includes pip) and you'll be able to install packages with pip as you are used to.
You might want to install some basic libraries first -
sudo apt-get install bzip2 libxml2-dev
Then install miniconda as given by #teoguso and restart your shell
source ~/.bashrc
You can then use conda or pip to install your packages

Installing moreutils on EC2 instance

How do I install moreutils on the default image Amazon EC2 instance? The instances are built off of CentOS but presumably have their own packages repo since
sudo yum install moreutils
fails with
No package moreutils available.
What is the yum repo I need to install moreutils?
The epel repo is on the default Amazon server but in not enabled by default. You can use it as follows:
sudo yum --enablerepo epel install moreutils
Note that epel has a very old version of moreutils (0.40 when 0.61 is out), which does not include chronic.
For update amazon linux, you can run following commands
sudo amazon-linux-extras install epel
sudo yum install moreutils
The EPEL repository has it, and other things. It works with Amazon Linux as well as CentOS, Fedora etc. (see http://fedoraproject.org/wiki/EPEL). To install the config that enables that repo, yum install epel-release.

Yum Update ansible version

I have ansible version 1.9 on my Centos 7 machine, but need to get version 1.9.2 as I'm running into compatibility issues with ansible and docker.
However, doing a yum update on the ansible package has no affect:
yum update -y ansible
No packages marked for update
How can I upgrade the package?
Edit:
I have upgraded the package using pip as suggested by #Eldad AK:
sudo pip install --upgrade ansible==1.9.2
And the upgrade appeared to be successful:
Successfully installed MarkupSafe-0.23 ansible-1.9.2 ecdsa-0.13 jinja2-2.8 paramiko-1.16.0 setuptools-20.7.0
However when i run the ansible executable and check the version, it's still at 1.9:
ansible --version
ansible 1.9 (devel affb66416f) last updated 2015/11/04 09:09:40 (GMT +100)
You can upgrade it using pip. Try
sudo pip install --upgrade ansible
This is how we update Ansible.
I hope this helps.
You probably have two versions of ansible installed:
1.9 installed via yum. Which is the one in your path and probably in /usr/bin/ansible.
1.9.2 installed via pip. Check /usr/lib/python-version/site-packages/, I guess there is an ansible-1.9.2-* directory there.
You can either uninstall the first one or include the second one in you PATH with a higher precedence.
A quick and dirty fix would be:
mv /usr/bin/ansible /usr/bin/ansible1.9 && mv /usr/bin/ansible-playbook /usr/bin/ansible-playbook1.9
ln -s /usr/lib/python-<version>/ansible-1.9.2-py[...].egg/EGG/scripts/ansible /usr/bin/ansible
ln -s /usr/lib/python-<version>/ansible-1.9.2-py[...].egg/EGG/scripts/ansible-playbook /usr/bin/ansible-playbook
sudo python -m pip uninstall ansible
sudo python -m pip install ansible

How to install pip in CentOS 7?

CentOS 7 EPEL now includes Python 3.4: yum install python34
However, when I try that, even though Python 3.4 installs successfully, it doesn't appear to install pip. Which is weird, because pip should be included by default with Python 3.4. which pip3 doesn't find anything, nor does which pip.
How do I access pip from the Python 3.4 package in CentOS 7 EPEL release?
The easiest way I've found to install pip3 (for python3.x packages) on CentOS 7 is:
$ sudo yum install python34-setuptools
$ sudo easy_install-3.4 pip
You'll need to have the EPEL repository enabled before hand, of course.
You should now be able to run commands like the following to install packages for python3.x:
$ pip3 install foo
curl https://bootstrap.pypa.io/get-pip.py | python3.4
Or if you don't have curl for some reason:
wget https://bootstrap.pypa.io/get-pip.py
python3.4 get-pip.py
After this you should be able to run
$ pip3
The CentOS 7 yum package for python34 does include the ensurepip module, but for some reason is missing the setuptools and pip files that should be a part of that module. To fix, download the latest wheels from PyPI into the module's _bundled directory (/lib64/python3.4/ensurepip/_bundled/):
setuptools-18.4-py2.py3-none-any.whl
pip-7.1.2-py2.py3-none-any.whl
then edit __init__.py to match the downloaded versions:
_SETUPTOOLS_VERSION = "18.4"
_PIP_VERSION = "7.1.2"
after which python3.4 -m ensurepip works as intended. Ensurepip is invoked automatically every time you create a virtual environment, for example:
pyvenv-3.4 py3
source py3/bin/activate
Hopefully RH will fix the broken Python3.4 yum package so that manual patching isn't needed.
Update: The python34 bug mentioned below has finally been fixed. It is a perfectly fine choice now.
Rather than using broken EPEL python34 packages, you can enable the IUS repo and have it work properly.
pip inside virtual environments
The main python34u and python35u IUS packages include the pyvenv tool (/usr/bin/pyvenv-3.4 or /usr/bin/pyvenv-3.5) that includes bundled wheels of pip and setuptools for bootstrapping virtual environments.
global pip
The python34u-pip and python35u-pip IUS packages include /usr/bin/pip3.4 and /usr/bin/pip3.5 respectively. These work just fine to install packages to the system site-packages directory.
yum install python34-pip
pip3.4 install foo
You will likely need the EPEL repositories installed:
yum install -y epel-release
Update 2019
I tried easy_install at first but it doesn't install packages in a clean and intuitive way. Also when it comes time to remove packages it left a lot of artifacts that needed to be cleaned up.
sudo yum install epel-release
sudo yum install python34-pip
pip install package
Was the solution that worked for me, it installs "pip3" as pip on the system. It also uses standard rpm structure so it clean in its removal. I am not sure what process you would need to take if you want both python2 and python3 package manager on your system.
Below are the steps I followed to install python34 and pip
yum update -y
yum -y install yum-utils
yum -y groupinstall development
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum makecache
yum -y install python34u python34u-pip
python3.6 -v
echo "alias python=/usr/bin/python3.4" >> ~/.bash_profile
source ~/.bash_profile
pip3 install --upgrade pip
# if yum install python34u-pip doesnt work, try
curl https://bootstrap.pypa.io/get-pip.py | python
There is a easy way of doing this by just using easy_install (A Setuptools to package python librarie).
Assumption.
Before doing this check whether you have python installed into your Centos machine (at least 2.x).
Steps to install pip.
So lets do install easy_install,
sudo yum install python-setuptools python-setuptools-devel
Now lets do pip with easy_install,
sudo easy_install pip
That's Great. Now you have pip :)
Figure out what version of python3 you have installed:
yum search pip
and then install the best match. Use reqoquery to find name of resulting pip3.e.g
repoquery -l python36u-pip
tells me to use pip3.6 instead of pip3
On CentOS 7, the pip version is pip3.4 and is located here:
/usr/local/bin/pip3.4

Resources