No package matching ‘python’ is available
failed: [161.35.226.85] (item=python) => {“ansible_loop_var”: “item”, “changed”: false, “item”: {“key”: “python”, “value”: “present”}}
Looks like python deb package is python3,
I set python → python3 in trellis/roles/common/defaults/main.yml
, and in worked.
1 Like
Glad you got it fixed 
Just a note that Trellis has handled this properly for at least a few years now so I’m assuming your project was quite old?
@dylanlawrence I apologize for hijacking your thread. Did you do anything special to make Trellis work (init/provision/deploy) on your 22.04 install? For the life of me, I can’t get it to work because I’m unable to interfere with the Python 3.10 that gets installed automatically.
@dylanlawrence I am getting the same error, how did you solve it? What changes did you make to trellis/roles/common/defaults/main.yml
?
@swalkinshaw Not OP, but I am getting the same error on an installation I did earlier this year. (I nuked staging and I am trying to re-provision it.)
I ssh’d into staging and created a symlink: ln -s /usr/bin/python /usr/bin/python3
but that didn’t help.
Any idea what to do or why ansible might want to install python
instead of python3
?
I ran trellis provision --verbose staging
and this is the traceback I get:
---------------------------------------------------
No package matching 'python' is available
The full traceback is:
File "/tmp/ansible_apt_payload_yw9ovx8e/ansible_apt_payload.zip/ansible/modules/apt.py", line 455, in package_status
File "/usr/lib/python3/dist-packages/apt/cache.py", line 287, in __getitem__
raise KeyError('The cache has no package named %r' % key)
failed: [5.75.245.117] (item={'key': 'python', 'value': 'present'}) => {
"ansible_loop_var": "item",
"changed": false,
"invocation": {
"module_args": {
"allow_unauthenticated": false,
"autoclean": false,
"autoremove": false,
"cache_valid_time": 3600,
"deb": null,
"default_release": null,
"dpkg_options": "force-confdef,force-confold",
"force": false,
"force_apt_get": false,
"install_recommends": null,
"name": "python",
"only_upgrade": false,
"package": [
"python"
],
"policy_rc_d": null,
"purge": false,
"state": "present",
"update_cache": null,
"update_cache_retries": 5,
"update_cache_retry_max_delay": 12,
"upgrade": null
}
},
"item": {
"key": "python",
"value": "present"
}
}
Are you using the Ubuntu 22.04 LTS server minimal setup? That system does not include python packages that interfere with python/ansible.
I’ve got a similar issue with another package python-boto
for the Trellis backup role.
So I added these lines to my group_vars/all/main.yml:
apt_packages_custom:
python-is-python3: "{{ apt_package_state }}"
python3-boto: "{{ apt_package_state }}"
python-is-python3
makes sure python
commands resolve to python3
, but it doesn’t resolve my issue, it still can’t find the python-boto
dependency when re-provisoning:
"No package matching 'python-boto' is available"
Anyone else bumping in to these issues?
It only happens on Ubuntu 22.04, the trellis-backup-role runs fine on 20.04?
I believe so! This is the same server image I provisioned to before.
This is the message I get after login:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-86-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Fri Oct 20 03:11:07 AM UTC 2023
System load: 0.22802734375 Processes: 95
Usage of /: 15.6% of 18.45GB Users logged in: 0
Memory usage: 13% IPv4 address for eth0: 5.75.245.117
Swap usage: 0% IPv6 address for eth0: 2a01:4f8:c012:850d::1
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
5 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
7 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm
I figured it out. As a friend of mine who worked in IT support used to quip, the problem is often located somewhere in the space between the user’s ears 
It seems this project is older than I recall. I created it with Ubuntu 20.04 LTS but the staging server I was trying to provision (after having nuked an older staging) ran Ubuntu 22.04 LTS. So it seems that’s what’s caused the hiccup.
I created a server with 20.04 and that solves the issues. I have now successfully provisioned it.
1 Like
What does this mean exactly?
This is my first project deployed to a Ubuntu 22.04
droplet, but it’s not installing/recognizing
the python-boto package:
python{{ system_python_version }}-boto
defined here in the ansible-backup role as dependency:
This system_python_version
variable is defined like this:
system_python_version: "{{ (ansible_distribution_release == 'focal') | ternary('3', '') }}"
So when I try to debug this {{ ansible_distribution_release }}
variable in my server.yml playbook as a pretask:
pre_tasks:
- debug:
var: ansible_distribution_release
- debug:
msg: "System python version: {{ (ansible_distribution_release == 'focal') | ternary('3', '') }}"
It outputs jammy:
TASK [debug] *******************************************************************
ok: [146.190.29.96] => {
"ansible_distribution_release": "jammy"
}
TASK [debug] *******************************************************************
ok: [146.190.29.96] => {
"msg": "System python version: "
}
While it should be focal in order to use python3
correct?
I used the standard Ubuntu 22.04 (LTS) x64 image in Digital Ocean.
When I ssh into my droplet both python --version
as well as python3 --version
return:
Python 3.10.12
So I guess this is a bug in the https://github.com/lafranceinsoumise/ansible-backup role?
Thanks!
Yes, system_python_version
is only set to 3
when ansible_distribution_release
is focal
, which is the code name for Ubuntu 20
. In any other case, it would be set to an empty string, as it is in your case with Ubuntu 22
(code name jammy
).
There are no python packages with just python-
for recent Ubuntu distributions, as it is the case with python-boto
(without the 3
) in Ubuntu repository, while package python3-boto
exists for Ubuntu jammy
.
This appears to be indeed a bug with the ansible-backup
role. You could just set system_python_version
to 3
for yourself and the provisioning should work correctly, as the python packages are found.
For a backwards-compatible, future-proof, potential PR that fixes the issue, one could modify the code so that the empty string (Python 2
) is used for everything below Ubuntu focal
. But just depending on code names for deciding the Python version of the python packages may not be the most ideal solution anyway.
2 Likes
Yes that works indeed! Adding this to my group_vars/all/main.yml
:
system_python_version: 3
Fixes the problem for me!
I submitted an issue at the ansible-backup role here.
Thanks for your help!
1 Like