- hosts: all
become: yes
tasks:
- name: Update apt repo and cache on all Debian/Ubuntu boxes
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
- name: Upgrade all packages on servers
apt: upgrade=dist force_apt_get=yes
- name: Autoremove unused packages
apt: autoremove=true
The output:
TASK [Update apt repo and cache on all Debian/Ubuntu boxes] ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [www4.example.org]: FAILED! => {"changed": false, "msg": "ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609]"}
fatal: [www3.example.org]: FAILED! => {"changed": false, "msg": "ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609]"}
Heh, I forgot to tell you to increase the verbosity so we would see what was returned by the second task. That being said, I think itâs safe to assume it should be 3.9.13 based on the path above.
This leads me to believe that this problem is specific to the Apt module being stuck with the platform version of python which is only python 3.5 in Ubuntu 16.04. Are you able to perform OS upgrades up to 20.04+? Ubuntu 16.04 and 18.04 are already EOL.
If not (or if thatâs part of the objective with this playbook), then you may need to use command/shell or even the raw modules to do what you need to with apt.
Based on a recent issue that was closed as âwontfixâ essentially, you will have to install python2.7-apt on the host (if it doesnât have it already) and specifically use python2 as the interpreter. I think you can set the interpreter as a var specifically for the apt module steps.
- hosts: all
become: yes
tasks:
- name: Update apt repo and cache on all Debian/Ubuntu boxes
apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
vars:
ansible_python_interpreter: /usr/bin/python2
- name: Upgrade all packages on servers
apt: upgrade=dist force_apt_get=yes
vars:
ansible_python_interpreter: /usr/bin/python2
- name: Autoremove unused packages
apt: autoremove=true
vars:
ansible_python_interpreter: /usr/bin/python2
Unfortunately, that doesnât work either⌠what a pity.
FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "failed": true, "msg": "ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.5.2 (default, Jan 26 2021, 13:30:48) [GCC 5.4.0 20160609]"}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
I think Iâll give up on this project now and hope that the machines will be retired soon.
Did you unset the ansible_python_interpreter in inventory? You wouldnât need to; we just want to override apt and which will take precedence over inventory vars. If gather_facts doesnât work in spite of specifying the python3.9 available your venv, I guess youâll have to set the interpreter to python2 by default then.
The only alternative I see is to specifically install an older version of ansible on your control node to handle these. Since you seem to be familiar with venvâs already, you could make one specifically for installing an older version of ansible. I think ansible-core~=2.11.0 or ~=2.12.0 might be able to bridge the gap. `pip install âansible>=4.0.0,<5.0.0â in your venv (or âansible>=5.0.0,<6.0.0â for core 2.12) and see if itâs okay with the discovered interpreters. (if youâre using AWX/AAP, you can also create a custom EE with an older vs of ansible to do this)
Regardless, they definitely need to be upgraded or retired. Iâm in a similar boat with RHEL 7 going EOL in June. Good luck!