apt icon indicating copy to clipboard operation
apt copied to clipboard

Patch to fix: "ANXS.apt : APT | Install Packages failed with No package(s) matching '['python3-apt'' available" error

Open ianheggie opened this issue 2 years ago • 2 comments

I refactored out the combining of the two lists (see patch below) and that fixed the problem for me!

Environment:

  • roles/ANXS.apt/version: v2.1.0
  • ansible --version: ansible [core 2.14.6]
  • ansible_python_interpreter: /usr/bin/python3
  • os-release (host and target): VERSION="22.04.2 LTS (Jammy Jellyfish)"
  • defaults/main.yml vars not overriden

Log from ansible:

TASK [ANXS.apt : APT | Reset the sources list (/etc/apt/sources.list)] ************************************************************************************************************************************************************************************************************
skipping: [staging3.server.tld]

TASK [ANXS.apt : APT | Update the apt cache] **************************************************************************************************************************************************************************************************************************************
ok: [staging3.server.tld]

TASK [ANXS.apt : APT | Remove packages that are no longer needed for dependencies] ************************************************************************************************************************************************************************************************
ok: [staging3.server.tld]

TASK [ANXS.apt : APT | Remove .deb files for packages no longer on your system] ***************************************************************************************************************************************************************************************************
ok: [staging3.server.tld]

TASK [ANXS.apt : APT | Check for cached .deb files] *******************************************************************************************************************************************************************************************************************************
skipping: [staging3.server.tld]

TASK [ANXS.apt : APT | Remove all cached .deb files] ******************************************************************************************************************************************************************************************************************************
skipping: [staging3.server.tld]

TASK [ANXS.apt : APT | Update the general configuration (/etc/apt/apt.conf.d/10general)] ******************************************************************************************************************************************************************************************
ok: [staging3.server.tld]

TASK [ANXS.apt : APT | Make sure the required packages are installed 20.04 and above] *********************************************************************************************************************************************************************************************
ok: [staging3.server.tld]

TASK [ANXS.apt : APT | Make sure the required packages are installed 19.10 and below] *********************************************************************************************************************************************************************************************
skipping: [staging3.server.tld]

TASK [ANXS.apt : APT | Install Packages] ******************************************************************************************************************************************************************************************************************************************
failed: [staging3.server.tld] (item=['python3-apt', 'unattended-upgrades', 'apt-transport-https', 'curl', 'ca-certificates', 'software-properties-common'] + ['python3-apt']) => {"ansible_loop_var": "item", "changed": false, "item": "['python3-apt', 'unattended-upgrades', 'apt-transport-https', 'curl', 'ca-certificates', 'software-properties-common'] + ['python3-apt']", "msg": "No package(s) matching '['python3-apt'' available"}
	to retry, use: --limit @/home/ianh/Projects/Xbase/provision/tmp/ansible-retry/site.retry

PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************************
staging3.server.tld        : ok=6    changed=0    unreachable=0    failed=1    skipped=4    rescued=0    ignored=0   

Patch that fixed the problem for me (personally prefer running apt on default separately from version specific list anyway)

diff --git a/roles/ANXS.apt/tasks/main.yml b/roles/ANXS.apt/tasks/main.yml
index c7382dc..a4a9d2c 100644
--- a/roles/ANXS.apt/tasks/main.yml
+++ b/roles/ANXS.apt/tasks/main.yml
@@ -43,17 +43,19 @@
     group: root
     mode: 0644
 
+- name: APT | Install Default Packages
+  apt:
+    pkg: "{{apt_default_packages}}"
+    state: present
+
 - name: APT | Make sure the required packages are installed 20.04 and above
-  set_fact:
-    apt_packages_list: "{{ apt_default_packages }} + {{ apt_default_packages_post20 }}"
+  apt:
+    pkg: "{{apt_default_packages_post20}}"
+    state: present
   when: ansible_facts['distribution_version'] is version('20.04', '>=')
 
 - name: APT | Make sure the required packages are installed 19.10 and below
-  set_fact:
-    apt_packages_list: "{{ apt_default_packages }} + {{ apt_default_packages_pre20 }}"
+  apt:
+    pkg: "{{apt_default_packages_pre20}}"
+    state: present
   when: ansible_facts['distribution_version'] is version('20.04', '<')
-
-- name: APT | Install Packages
-  apt:
-    pkg: "{{apt_packages_list}}"
-    state: present

ianheggie avatar Jun 10 '23 06:06 ianheggie

@ianheggie actually the issue is related to changed arithmetic and concatenation operations outside of the jinja template. The solution is to change this {{ apt_default_packages }} + {{ apt_default_packages_pre20 }} to this {{ apt_default_packages + apt_default_packages_pre20 }}

edit: I've just realized that the fix is already merged ;)

nekeal avatar Jul 07 '23 13:07 nekeal

@ianheggie actually the issue is related to changed arithmetic and concatenation operations outside of the jinja template. The solution is to change this {{ apt_default_packages }} + {{ apt_default_packages_pre20 }} to this {{ apt_default_packages + apt_default_packages_pre20 }}

edit: I've just realized that the fix is already merged ;)

Thanks for your feedback - I didn't twig to that being the issue. I was just reading about "egg of Columbus" and your solution fits!

ianheggie avatar Jul 07 '23 16:07 ianheggie