Skip to content

Commit 0e27a34

Browse files
committed
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 <abelur@linuxfoundation.org>
1 parent 16ced97 commit 0e27a34

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

.github/workflows/gerrit-verify.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ jobs:
111111
strategy:
112112
matrix:
113113
distro:
114+
- centos9
114115
- ubuntu2204
115116
- ubuntu2404
116117
fail-fast: false

molecule/default/molecule.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ dependency:
44
driver:
55
name: podman
66
platforms:
7+
- name: centos9
8+
image: quay.io/centos/centos:stream9
9+
pre_build_image: false
710
- name: ubuntu2204
811
image: ubuntu:22.04
912
pre_build_image: false
@@ -12,13 +15,29 @@ platforms:
1215
pre_build_image: false
1316
provisioner:
1417
name: ansible
15-
env:
16-
ANSIBLE_CONFIG: ${MOLECULE_PROJECT_DIRECTORY}/ansible.cfg
18+
config_options:
19+
defaults:
20+
callbacks_enabled: profile_tasks
21+
inject_facts_as_vars: false
1722
inventory:
1823
host_vars:
24+
centos9:
25+
ansible_python_interpreter: /usr/bin/python3
1926
ubuntu2204:
2027
ansible_python_interpreter: /usr/bin/python3
2128
ubuntu2404:
2229
ansible_python_interpreter: /usr/bin/python3
30+
scenario:
31+
name: default
32+
test_sequence:
33+
- destroy
34+
- dependency
35+
- syntax
36+
- create
37+
- prepare
38+
- converge
39+
- side_effect
40+
- verify
41+
- destroy
2342
verifier:
2443
name: ansible

tasks/Debian.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
until: task_result is success
1616
retries: 3
1717
delay: 10
18+
when: ansible_facts['distribution_version'] is version('24.04', '<')
1819

1920
- name: Install OpenJDK 1.8.0, 11 and 12
2021
ansible.builtin.package:
@@ -26,7 +27,7 @@
2627
update_cache: 'yes'
2728
become: true
2829
when:
29-
- ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=')
30+
- ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
3031

3132
- name: Install OpenJDK 17
3233
ansible.builtin.package:
@@ -36,8 +37,8 @@
3637
update_cache: 'yes'
3738
become: true
3839
when:
39-
- ansible_os_family == "Debian"
40-
- ansible_distribution_major_version == "11" or ansible_distribution_version >= "18.04"
40+
- ansible_facts['os_family'] == "Debian"
41+
- ansible_facts['distribution_major_version'] == "11" or ansible_facts['distribution_version'] is version('18.04', '>=')
4142

4243
- name: Install OpenJDK 21
4344
apt:
@@ -47,25 +48,26 @@
4748
update_cache: 'yes'
4849
become: true
4950
when:
50-
- ansible_os_family == "Debian"
51-
- ansible_distribution_major_version == "13" or ansible_distribution_version >= "20.04"
51+
- ansible_facts['os_family'] == "Debian"
52+
- ansible_facts['distribution_major_version'] == "13" or ansible_facts['distribution_version'] is version('20.04', '>=')
5253

5354
- name: Set Java path for OpenJDK 11 (non-arm)
5455
ansible.builtin.set_fact:
5556
java_path: /usr/lib/jvm/java-1.11.0-openjdk-amd64
5657
when:
57-
- ansible_architecture != "aarch64"
58-
- ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=')
58+
- ansible_facts['architecture'] != "aarch64"
59+
- ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
5960

6061
- name: Set Java path for OpenJDK 11 (arm)
6162
ansible.builtin.set_fact:
6263
java_path: /usr/lib/jvm/java-1.11.0-openjdk-arm64
6364
when:
64-
- ansible_architecture == "aarch64"
65+
- ansible_facts['architecture'] == "aarch64"
66+
- ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '<=')
6567

6668
- name: Set Java path for OpenJDK 21 (non-arm)
6769
ansible.builtin.set_fact:
6870
java_path: /usr/lib/jvm/java-1.21.0-openjdk-amd64
6971
when:
70-
- ansible_architecture != "aarch64"
71-
- ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '>=')
72+
- ansible_facts['architecture'] != "aarch64"
73+
- ansible_facts['os_family'] == 'Debian' and ansible_facts['distribution_version'] is version('20.04', '>=')

tasks/RedHat.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name:
55
- epel-release
66
state: present
7-
when: ansible_os_family == "RedHat"
7+
when: ansible_facts['os_family'] == "RedHat"
88
become: true
99

1010
- name: Install OpenJDK 1.8.0, 11
@@ -21,7 +21,7 @@
2121
- java-17-openjdk-devel
2222
- java-latest-openjdk-devel
2323
state: present
24-
when: ansible_os_family == "RedHat" and ansible_distribution_major_version == "8"
24+
when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] == "8"
2525
become: true
2626

2727
- name: Install OpenJDK 21, latest
@@ -30,7 +30,7 @@
3030
- java-21-openjdk-devel
3131
- java-latest-openjdk-devel
3232
state: present
33-
when: ansible_os_family == "RedHat" and ansible_distribution_major_version >= "8"
33+
when: ansible_facts['os_family'] == "RedHat" and ansible_facts['distribution_major_version'] is version('9', '>=')
3434
become: true
3535

3636
- name: Set Java path for OpenJDK 11

tasks/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
- name: Install JDK for {{ ansible_os_family }}
2+
- name: Install JDK for {{ ansible_facts['os_family'] }}
33
ansible.builtin.include_tasks: '{{ item }}'
44
with_first_found:
5-
- '{{ ansible_os_family }}-{{ ansible_architecture }}.yml'
6-
- '{{ ansible_distribution }}.yml'
7-
- '{{ ansible_os_family }}.yml'
5+
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["architecture"] }}.yml'
6+
- '{{ ansible_facts["distribution"] }}.yml'
7+
- '{{ ansible_facts["os_family"] }}.yml'
88

99
- name: Set default Java
1010
become: true

0 commit comments

Comments
 (0)