From 6c64a4caec3014def282edcb1b9cac5c05e4ee88 Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <andrea.dellamico@isti.cnr.it>
Date: Fri, 20 Dec 2024 15:17:27 +0100
Subject: [PATCH] Install the python packages as deb in ubuntu >= 22.04.

---
 tasks/deb_pkgs.yml | 8 ++++++++
 vars/main.yml      | 8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tasks/deb_pkgs.yml b/tasks/deb_pkgs.yml
index 938adf1..fc8b741 100644
--- a/tasks/deb_pkgs.yml
+++ b/tasks/deb_pkgs.yml
@@ -39,6 +39,14 @@
         force: true
       when: docker_specific_package_ver
 
+    - name: Install some pyton 3 packages required by ansible
+      ansible.builtin.apt:
+        pkg: "{{ docker_python_deb_pkgs }}"
+        state: present
+        cache_valid_time: 3600
+        force: true
+      when: not py3_env_install
+
 - name: Remove the docker packages and repository
   when: not docker_install | bool
   tags: [docker, docker_pkg]
diff --git a/vars/main.yml b/vars/main.yml
index 0bdd41a..bc8f538 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,5 +1,7 @@
 ---
-py3_env_install: True
+py3_external_env_install: '{% if ansible_distribution_version is version_compare("22.04", "<") %}true{% else %}false{% endif %}'
+py3_env_install: '{{ py3_external_env_install | bool }}'
+
 py3_env_pip_pkgs:
   - docker
   - jsondiff
@@ -8,6 +10,10 @@ py3_env_versioned_pip_pkgs:
   - pkg: "requests"
     version: "2.29.0"
 
+docker_python_deb_pkgs:
+  - python3-docker
+  - python3-jsondiff
+
 docker_deb_repo_key_url: 'https://download.docker.com/linux/ubuntu/gpg'
 # Set to the Debian distribution name if not Ubuntu
 docker_linux_distribution: '{{ ansible_distribution_release | lower }}'