From 2ecb159cbcaaa6473bb3c45eb3c395dcefdd4ee9 Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Sun, 11 Feb 2024 12:20:35 +1000 Subject: [PATCH] Fix: Update java-install ansible role Update molecule test formats and update the role to build with latest version of ansible. Fix ansible lint errors and warnings. Update tox and pre-commit dependencies to build with latest versions of ansible and molecule. Change-Id: I448505ad7259a238ad8f5e5e65a210fe587fb96f Signed-off-by: Anil Belur --- .github/workflows/gerrit-verify.yaml | 2 +- .yamllint | 4 +--- meta/main.yml | 3 ++- molecule/default/molecule.yml | 4 ---- tasks/Debian.yml | 14 ++++++++------ tasks/RedHat.yml | 13 ++++++++----- tasks/main.yml | 19 ++++++++++--------- tox.ini | 30 ++++++++++++++++++++---------- 8 files changed, 50 insertions(+), 39 deletions(-) diff --git a/.github/workflows/gerrit-verify.yaml b/.github/workflows/gerrit-verify.yaml index 72aa927..fdf4d76 100644 --- a/.github/workflows/gerrit-verify.yaml +++ b/.github/workflows/gerrit-verify.yaml @@ -124,7 +124,7 @@ jobs: env: PY_COLORS: "1" ANSIBLE_FORCE_COLOR: "1" - MOLECULE_DISTRO: ${{ matrix.distro }} + MOLECULE_PLATFORM_NAME: ${{ matrix.distro }} vote: if: ${{ always() }} diff --git a/.yamllint b/.yamllint index 7626c6e..894450c 100644 --- a/.yamllint +++ b/.yamllint @@ -9,9 +9,7 @@ rules: max-spaces-inside: 1 level: error line-length: disable - # NOTE(retr0h): Templates no longer fail this lint rule. - # Uncomment if running old Molecule templates. - # truthy: disable + truthy: disable ignore: | .tox/ diff --git a/meta/main.yml b/meta/main.yml index e4940e0..3b80d2f 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -16,12 +16,13 @@ galaxy_info: versions: - 7 - 8 + - 9 - name: Ubuntu versions: - - xenial - bionic - focal + - jammy galaxy_tags: - java diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index a5bbab2..bce15f1 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -3,10 +3,6 @@ dependency: name: galaxy driver: name: docker -lint: | - set -e - yamllint . - ansible-lint tasks/*.yml platforms: - name: centos7 image: centos:7 diff --git a/tasks/Debian.yml b/tasks/Debian.yml index 094c606..2986cbd 100644 --- a/tasks/Debian.yml +++ b/tasks/Debian.yml @@ -1,6 +1,6 @@ --- - name: Install ppa pre-requsites - apt: + ansible.builtin.package: name: - gnupg2 state: present @@ -8,7 +8,7 @@ become: true - name: Setup openjdk-r/ppa - apt_repository: + ansible.builtin.apt_repository: repo: 'ppa:openjdk-r/ppa' become: true register: task_result @@ -17,7 +17,7 @@ delay: 10 - name: Install OpenJDK 1.8.0, 11 and 12 - apt: + ansible.builtin.package: name: - openjdk-8-jdk - openjdk-11-jdk @@ -25,9 +25,11 @@ state: present update_cache: 'yes' become: true + when: + - ansible_os_family == 'Debian' and ansible_facts['distribution_major_version'] is version('20.04', '<=') - name: Install OpenJDK 17 - apt: + ansible.builtin.package: name: - openjdk-17-jdk state: present @@ -39,13 +41,13 @@ ansible_distribution_version == "18.04" - name: Set Java path for OpenJDK 11 (non-arm) - set_fact: + ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-1.11.0-openjdk-amd64 when: - ansible_architecture != "aarch64" - name: Set Java path for OpenJDK 11 (arm) - set_fact: + ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-1.11.0-openjdk-arm64 when: - ansible_architecture == "aarch64" diff --git a/tasks/RedHat.yml b/tasks/RedHat.yml index af901a6..96c1433 100644 --- a/tasks/RedHat.yml +++ b/tasks/RedHat.yml @@ -1,11 +1,14 @@ --- - name: Install Epel Repo - package: name=epel-release state=present + ansible.builtin.yum: + name: + - epel-release + state: present when: ansible_os_family == "RedHat" become: true - name: Install OpenJDK 1.8.0, 11 - yum: + ansible.builtin.yum: name: - java-1.8.0-openjdk-devel - java-11-openjdk-devel @@ -13,7 +16,7 @@ become: true - name: Install OpenJDK 17, latest - yum: + ansible.builtin.yum: name: - java-17-openjdk-devel - java-latest-openjdk-devel @@ -22,7 +25,7 @@ become: true - name: Install OpenJDK 21, latest - yum: + ansible.builtin.yum: name: - java-21-openjdk-devel - java-latest-openjdk-devel @@ -31,5 +34,5 @@ become: true - name: Set Java path for OpenJDK 11 - set_fact: + ansible.builtin.set_fact: java_path: /usr/lib/jvm/java-11-openjdk diff --git a/tasks/main.yml b/tasks/main.yml index 2f39063..228a16c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,45 +1,46 @@ --- -- include_tasks: '{{ item }}' +- name: Install JDK for {{ ansible_os_family }} + ansible.builtin.include_tasks: '{{ item }}' with_first_found: - '{{ ansible_os_family }}-{{ ansible_architecture }}.yml' - '{{ ansible_distribution }}.yml' - '{{ ansible_os_family }}.yml' - name: Set default Java + become: true block: - name: Set java alternatives - alternatives: + community.general.alternatives: name: java link: /usr/bin/java path: '{{ java_path }}/bin/java' - name: Set javac alternatives - alternatives: + community.general.alternatives: name: javac link: /usr/bin/javac path: '{{ java_path }}/bin/javac' - name: Set jar alternatives - alternatives: + community.general.alternatives: name: jar link: /usr/bin/jar path: '{{ java_path }}/bin/jar' - name: Set jarsigner alternatives - alternatives: + community.general.alternatives: name: jarsigner link: /usr/bin/jarsigner path: '{{ java_path }}/bin/jarsigner' - name: Set javadoc alternatives - alternatives: + community.general.alternatives: name: javadoc link: /usr/bin/javadoc path: '{{ java_path }}/bin/javadoc' - name: Set javap alternatives - alternatives: + community.general.alternatives: name: javap link: /usr/bin/javap path: '{{ java_path }}/bin/javap' - name: Set java_sdk_openjdk alternatives - alternatives: + community.general.alternatives: name: java_sdk_openjdk link: /usr/lib/jvm/java-openjdk path: '{{ java_path }}/bin/java' - become: true diff --git a/tox.ini b/tox.ini index d0929c3..5ad109a 100644 --- a/tox.ini +++ b/tox.ini @@ -2,20 +2,17 @@ minversion = 1.6 envlist = molecule, - pre-commit + pre-commit, + lint skipsdist=true [testenv:molecule] basepython = python3 deps = - ansible~=2.9.6 - ansible-lint~=4.2.0 - detox~=0.18 + ansible docker - yamllint - molecule~=3.0.8 - molecule[docker] - pytest~=5.4.0 + molecule + molecule-docker passenv = * commands = ./molecule.sh @@ -23,9 +20,10 @@ allowlist_externals = ./molecule.sh [testenv:pre-commit] -basepython = python3 +allowlist_externals = + /bin/sh deps = pre-commit -allowlist_externals = /bin/sh +passenv = HOME commands = pre-commit run --all-files --show-diff-on-failure /bin/sh -c 'if ! git config --get user.name > /dev/null; then \ @@ -45,3 +43,15 @@ commands = /bin/sh -c "if [ -f .git/REMOVE_USEREMAIL ]; then \ git config --global --unset user.email; \ rm -f .git/REMOVE_USEREMAIL; fi" + +[testenv:lint] +basepython = python310 +deps = + ansible-lint + yamllint +commands = + /bin/bash -c "ansible-lint tasks/*.yml" + yamllint . +allowlist_externals = + /bin/bash + yamllint -- 2.16.6