Reputation: 175
When I run the following command: ansible-playbook --version
, I get the results:
ansible-playbook 2.5.0
config file = /home/dev/sources/Installation/ansible.cfg
configured module search path = ['/home/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
The thing is that I'd like Python 2.7.8 in the location instead of 3.8.10.
I configured the ansible.cfg
file as follows:
[defaults]
# SSH key host checking
host_key_checking=false
allow_world_readable_tmpfiles=true
roles_path=./roles/:../../Installation/roles/
filter_plugins=./filter_plugins/:../../Installation/filter_plugins/
ansible_python_interpreter=/opt/Python-2.7.8/python/
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
... and when I run the ansible-playbook --version
command again, it still points to Python 3.8. What am I doing wrong? I also tried to define python variable in playbook vars (ansible_python_interpreter: /opt/Python-2.7.8/python/)
, however without the success.
Upvotes: 1
Views: 3549
Reputation: 6772
ansible is a python package that consists of a couple of executables like ansible
, ansible-playbook
, ansible-galaxy
. If you want to use Python 2.7 then you should ensure that ansible is installed as a library for that python, and that the executables of that install are in your PATH variable etc. One way to do that is by using virtualenv
, which creates a copy of Python 2.7 that you can activate just for that project of yours. python-virtualenv is a package for your operating system. Once you've installed it you can run:
virtualenv -p /usr/bin/python2.7 py27
source py27/bin/activate
pip install ansible==2.5.0
ansible-playbook --version
Please note that Python 2.7 was EOL January 1, 2020, and Ansible 2.8 and earlier are outdated and are no longer updated by the community. (Although still supported by some vendors)
Upvotes: 2