From: Anil Belur Date: Mon, 15 Dec 2025 12:14:20 +0000 (+1000) Subject: fix: Update tasks to use ansible_facts dictionary X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=0e27a3458e3c0fe30cf8e6772bc31303f0c02121;p=ansible%2Froles%2Fjava-install.git fix: Update tasks to use ansible_facts dictionary - Replace ansible_os_family with ansible_facts['os_family'] - Replace ansible_architecture with ansible_facts['architecture'] - Replace ansible_distribution_* with ansible_facts['distribution_*'] - Fix version comparisons to use is version() test - Update CentOS 9 condition to use >= instead of exact match Change-Id: I71524fd294652e4b7993e41d1751957d15d4b0f5 Signed-off-by: Anil Belur --- diff --git a/.github/workflows/gerrit-verify.yaml b/.github/workflows/gerrit-verify.yaml index 2eae8b1..2253324 100644 --- a/.github/workflows/gerrit-verify.yaml +++ b/.github/workflows/gerrit-verify.yaml @@ -111,6 +111,7 @@ jobs: strategy: matrix: distro: + - centos9 - ubuntu2204 - ubuntu2404 fail-fast: false diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 007e8f2..008423c 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -4,6 +4,9 @@ dependency: driver: name: podman platforms: + - name: centos9 + image: quay.io/centos/centos:stream9 + pre_build_image: false - name: ubuntu2204 image: ubuntu:22.04 pre_build_image: false @@ -12,13 +15,29 @@ platforms: pre_build_image: false provisioner: name: ansible - env: - ANSIBLE_CONFIG: ${MOLECULE_PROJECT_DIRECTORY}/ansible.cfg + config_options: + defaults: + callbacks_enabled: profile_tasks + inject_facts_as_vars: false inventory: host_vars: + centos9: + ansible_python_interpreter: /usr/bin/python3 ubuntu2204: ansible_python_interpreter: /usr/bin/python3 ubuntu2404: ansible_python_interpreter: /usr/bin/python3 +scenario: + name: default + test_sequence: + - destroy + - dependency + - syntax + - create + - prepare + - converge + - side_effect + - verify + - destroy verifier: name: ansible diff --git a/tasks/Debian.yml b/tasks/Debian.yml index e318408..f9a6fd7 100644 --- a/tasks/Debian.yml +++ b/tasks/Debian.yml @@ -15,6 +15,7 @@ until: task_result is success retries: 3 delay: 10 + when: ansible_facts['distribution_version'] is version('24.04', '<') - name: Install OpenJDK 1.8.0, 11 and 12 ansible.builtin.package: @@ -26,7 +27,7 @@ update_cache: 'yes' become: true when: - - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=') + - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=') - name: Install OpenJDK 17 ansible.builtin.package: @@ -36,8 +37,8 @@ update_cache: 'yes' become: true when: - - ansible_os_family == "Debian" - - ansible_distribution_major_version == "11" or ansible_distribution_version >= "18.04" + - ansible_facts['os_family'] == "Debian" + - ansible_facts['distribution_major_version'] == "11" or ansible_facts['distribution_version'] is version('18.04', '>=') - name: Install OpenJDK 21 apt: @@ -47,25 +48,26 @@ update_cache: 'yes' become: true when: - - ansible_os_family == "Debian" - - ansible_distribution_major_version == "13" or ansible_distribution_version >= "20.04" + - ansible_facts['os_family'] == "Debian" + - ansible_facts['distribution_major_version'] == "13" or ansible_facts['distribution_version'] is version('20.04', '>=') - name: Set Java path for OpenJDK 11 (non-arm) ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-1.11.0-openjdk-amd64 when: - - ansible_architecture != "aarch64" - - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=') + - ansible_facts['architecture'] != "aarch64" + - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=') - name: Set Java path for OpenJDK 11 (arm) ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-1.11.0-openjdk-arm64 when: - - ansible_architecture == "aarch64" + - ansible_facts['architecture'] == "aarch64" + - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=') - name: Set Java path for OpenJDK 21 (non-arm) ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-1.21.0-openjdk-amd64 when: - - ansible_architecture != "aarch64" - - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '>=') + - ansible_facts['architecture'] != "aarch64" + - ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '>=') diff --git a/tasks/RedHat.yml b/tasks/RedHat.yml index dbc1a41..5396eb5 100644 --- a/tasks/RedHat.yml +++ b/tasks/RedHat.yml @@ -4,7 +4,7 @@ name: - epel-release state: present - when: ansible_os_family == "RedHat" + when: ansible_facts['os_family'] == "RedHat" become: true - name: Install OpenJDK 1.8.0, 11 @@ -21,7 +21,7 @@ - java-17-openjdk-devel - java-latest-openjdk-devel state: present - when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "8" + when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] == "8" become: true - name: Install OpenJDK 21, latest @@ -30,7 +30,7 @@ - java-21-openjdk-devel - java-latest-openjdk-devel state: present - when: ansible_os_family == "RedHat" and ansible_distribution_major_version >= "8" + when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('9', '>=') become: true - name: Set Java path for OpenJDK 11 diff --git a/tasks/main.yml b/tasks/main.yml index 228a16c..4d4ff18 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,10 @@ --- -- name: Install JDK for {{ ansible_os_family }} +- name: Install JDK for {{ ansible_facts['os_family'] }} ansible.builtin.include_tasks: '{{ item }}' with_first_found: - - '{{ ansible_os_family }}-{{ ansible_architecture }}.yml' - - '{{ ansible_distribution }}.yml' - - '{{ ansible_os_family }}.yml' + - '{{ ansible_facts["os_family"] }}-{{ ansible_facts["architecture"] }}.yml' + - '{{ ansible_facts["distribution"] }}.yml' + - '{{ ansible_facts["os_family"] }}.yml' - name: Set default Java become: true