-3

I am trying to get ansible 2.9 setup and configured on my Raspberry Pi 4 (Raspberry Pi OS 64bit) If I run ansible --version as a normal user, I get this:

ansible --version
ansible [core 2.11.4] 
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/stan/.ansible/plugins/modules', /usr/share/ansible/plugins/modules']
ansible python module location = /home/stan/.local/lib/python3.7/site-packages/ansible
ansible collection location = /home/stan/.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 = 2.10
libyaml = True

But when I run the same command as root, I get this:

ansible --version
ansible 2.9.25.post0
config file = /etc/ansible/ansible.cfg
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
executable location = /usr/local/bin/ansible
python version = 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]

BTW: Stackoverflow forced be to format the above as code, but it is not code, it is command output.

Why do I get two different results depending on what user is running the command? The bigger questions which version is installed 2.9.25 (root) or 2.11.4 (user)?

StanGreen
  • 79
  • 1
  • 6
  • 3
    You should run `which ansible` from both users. The output should be different for both. – P.... Aug 28 '21 at 01:55

1 Answers1

1

You have two different versions installed. One is 'system' (in /usr/local/lib/python3.7/dist-packages/ansible), and second is in user home directory: /home/stan/.local/lib/python3.7/site-packages/ansible

The 'system binary' in /usr/local/bin is just loading entry points via 'import' statement of Python, therefore, the actual ansible version you see is very dependent on your import pathes configuration.

The order of module loading is dependent on sys.path variable (of python).

>>> import sys
>>> sys.path

The source of sys.path is a very tricky question. (See What sets up sys.path with Python, and when?), but you may start from your .profile and PYTHONPATH environment variable.

George Shuklin
  • 6,952
  • 10
  • 39
  • 80