7

I am trying to install Ansible on CentOS 7, and have Ansible configured to use Python 3. I've both Python2 and Python3 installed.

[root@ansible1 ~]# python --version
Python 2.7.5
[root@ansible1 ~]# python3 --version
Python 3.6.8

If I install Ansible using yum install ansible, the ansible --version command shows that Ansible is configured to use Python 2.7.5. I uninstall ansible (yum remove ansible);

[root@ansible1 ~]# ansible --version
ansible 2.9.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

According to https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html:

The easiest way to run /usr/bin/ansible under Python 3 is to install it with the Python3 version of pip. This will make the default /usr/bin/ansible run with Python3

I have version 9.0.3 of pip installed.

[root@ansible1 ~]# pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

Following Ansibles documentation, I issue pip3 install ansible to install Ansible using pip3.

[root@ansible1 ~]# pip3 install ansible
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting ansible
  Using cached https://files.pythonhosted.org/packages/4b/69/c8aef60ce070fe6872e27db65f588bd0ffe8892a980cd3f4d844d8b72152/ansible-2.9.12.tar.gz
Requirement already satisfied: jinja2 in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: PyYAML in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: cryptography in /usr/local/lib64/python3.6/site-packages (from ansible)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib64/python3.6/site-packages (from jinja2->ansible)
Requirement already satisfied: six>=1.4.1 in /usr/local/lib/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/local/lib64/python3.6/site-packages (from cryptography->ansible)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography->ansible)
Installing collected packages: ansible
  Running setup.py install for ansible ... done
Successfully installed ansible-2.9.12

Here is the output of the pip3 show ansible command.

[root@ansible1 ~]# pip3 show ansible
Name: ansible
Version: 2.9.12
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /usr/local/lib/python3.6/site-packages
Requires: jinja2, PyYAML, cryptography

However, the ansible --version command returns the following.

-bash: /bin/ansible: No such file or directory

Likewise, /usr/bin/ansible --version:

-bash: /usr/bin/ansible: No such file or directory

The pip show ansible command shows that the location is /usr/local/lib/python3.6/site-packages/ansible. This directory exists, and contains many files and folders, but no Ansible specific configuration files (e.g. ansible.cfg) or binary files (e.g. ansible) that can be used (best I can tell).

2
  • what says ls -l /bin/ansible -- maybe it's a dead link pointing nowhere, created maybe through a previous installation of ansible?
    – Petter H
    Aug 17, 2020 at 10:24
  • ls /bin/ansible (or /sbin/ansible, or /usr/bin/ansible) all return something like ls: cannot access /bin/ansible: No such file or directory Aug 17, 2020 at 10:32

1 Answer 1

12

Bash caches the paths to commands, and if a command is relocated (as it appears to be in your case) then bash will not pick it up unless that cache is cleared.

You can clear ansible from the cache with:

hash -d ansible

Or clear the entire cache with:

hash -r
2
  • 1
    Amazing, that resolved it. That's going straight into my personal notes. Thanks a ton! Aug 17, 2020 at 10:43
  • Any modification to $PATH will also clear the cache (since the cache contains paths found by searching $PATH), so I use PATH=$PATH which I find easier to remember.
    – jrw32982
    Aug 24, 2020 at 18:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .