10

I have installed Ansible via pip3, but I can't find the Ansible commands (ansible --version, ansible-playbook, etc.)

Here's the listing that shows that Ansible is installed via pip3:

:~# pip3 list  | grep ansible
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ansible (3.1.0)
ansible-base (2.10.7)

But I can find no file or what so ever in /usr/bin and the commands are not found:

:~/.ansible# ls -ltrha
total 12K
drwx------ 3 root root 4.0K Feb  3 11:42 .
drwx------ 3 root root 4.0K Mar 19 16:01 tmp
drwx------ 8 root root 4.0K Mar 22 15:34 ..

Do I need to configure something? Is my installation done improperly?

I use Debian GNU/Linux 9 (stretch)

2
  • 3
    If you used pip3 as a superuser you should check if Ansible installed cli tools to /usr/local/bin. If installed as a user you should check ~/.local/bin. Either way add that to your PATH
    – micke
    Commented Mar 25, 2021 at 22:44
  • @micke that's true I found it so I did reinstall it without using root which is the proper way
    – Jinja_dude
    Commented Mar 26, 2021 at 9:59

5 Answers 5

5

Add the ~/.local/bin to PATH environment variable You can do it by Executing the below command in your Unix terminal

export PATH=$PATH:~/.local/bin
2

I got the same on my ubuntu WSL installation. Just uninstall it using:

python3 -m pip uninstall ansible

Move to home directory:

cd ~

Your prompt will show :~$

Reinstall it again:

python3 -m pip install --user ansible

Now it is working :)

:~$ ansible --version
ansible [core 2.13.1]
config file = None
configured module search path = ['/home/evert/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/evert/.local/lib/python3.8/site-packages/ansible
ansible collection location = /home/evert/.ansible/collections:/usr/share/ansible/collections
executable location = /home/evert/.local/bin/ansible
python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
jinja version = 3.1.2
libyaml = True
1
  • only works if you don't have elevated privileges (e.g. used sudo recently)
    – JFFIGK
    Commented Apr 5, 2023 at 15:13
1

This situation tends to happen as @micke commented - while using pip3 as root user - the installed CLI tool may end up in a directory that's not included in $PATH environment variable - then you need to adjust $PATH.

Tested on Debian10 all performs as expected:

root@d10:~# pip3 install ansible
Collecting ansible
  Downloading https://files.pythonhosted.org/packages/fd/f8/071905c6a67592d0852a9f340f6ab9226861eeeb97fdf4068642b22edcf3/ansible-4.10.0.tar.gz (36.8MB)
    100% |████████████████████████████████| 36.8MB 35kB/s 
#pip3 install log truncated...
 root@d10:~# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.7.3 (default, Jan 22 2021, 
20:04:44) [GCC 8.3.0]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.7] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]
  jinja version = 3.0.3
  libyaml = True
root@d10:~# which ansible
/usr/local/bin/ansible
1
  • "This situation tends to happen as @micke commented - while using pip3 as root user " this was exactly what caused the problem for me
    – JFFIGK
    Commented Apr 5, 2023 at 15:12
0

Use this command

cp .local/bin/ansible  /usr/local/bin

or

mv .local/bin/ansible /usr/local/bin

root@DESKTOP-3PFRNOB:~# ansible
usage: ansible [-h] [--version] [-v] [-b] [--become-method BECOME_METHOD] [--become-user BECOME_USER] [-K | --become-password-file BECOME_PASSWORD_FILE] [-i INVENTORY] 
0

You can add the path to your .bashrc so it get loaded for every terminal session

~/.bashrc

if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

reload your bashrc, run this or close all shells and reopen

source ~/.bashrc

if all working, you should see the path to your binary when running which ansible

You must log in to answer this question.

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