diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 00000000..3d966877 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,6 @@ +--- +profile: production +exclude_paths: + - .github/ + - .travis.yml + - molecule/default/yaml-lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..6065f721 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +--- +name: CI +on: + - push + - pull_request + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install lint dependencies + run: pip3 install "ansible==14.*" "ansible-lint==26.*" "yamllint==1.*" + + - name: Lint YAML + run: yamllint . + + - name: Lint Ansible + run: ansible-lint + + test: + name: Molecule + needs: lint + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + distro: + - ubuntu2204 + - ubuntu2404 + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + path: "${{ github.repository }}" + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install test dependencies + run: pip3 install "ansible==14.*" "molecule==26.*" "molecule-plugins[docker]==26.*" docker + + - name: Run Molecule tests + working-directory: "${{ github.repository }}" + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/.gitignore b/.gitignore index f56f5b57..0e4d8331 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.retry */__pycache__ *.pyc +.ansible/ diff --git a/.yamllint b/.yamllint new file mode 100644 index 00000000..fe6258fb --- /dev/null +++ b/.yamllint @@ -0,0 +1,20 @@ +--- +extends: default + +rules: + comments: + min-spaces-from-content: 1 + comments-indentation: false + braces: + max-spaces-inside: 1 + octal-values: + forbid-implicit-octal: true + forbid-explicit-octal: true + line-length: + max: 160 + truthy: + allowed-values: ["true", "false"] + check-keys: false + +ignore: | + .travis.yml diff --git a/defaults/main.yml b/defaults/main.yml index d605cd69..b7253c7e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,4 +6,4 @@ java_home: "" # Whether to set the installed Java binary as the default java. You will need # to set java_home too for this to be done -java_set_default: true \ No newline at end of file +java_set_default: true diff --git a/meta/main.yml b/meta/main.yml index 20b9f75a..ea071e9f 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,17 +3,18 @@ dependencies: [] galaxy_info: role_name: java + namespace: onaio author: geerlingguy description: Java for Linux company: "Midwestern Mac, LLC" license: "license (BSD, MIT)" - min_ansible_version: 2.4 + min_ansible_version: "2.4" platforms: - name: EL versions: - - 6 - - 7 - - 8 + - "6" + - "7" + - "8" - name: Fedora versions: - all @@ -29,9 +30,11 @@ galaxy_info: - trusty - xenial - bionic + - jammy + - noble - name: FreeBSD versions: - - 10.2 + - "10.2" galaxy_tags: - development - system diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 2ca6feaf..69f9353d 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,29 +1,23 @@ --- dependency: name: galaxy + enabled: false driver: name: docker -lint: - name: yamllint - options: - config-file: molecule/default/yaml-lint.yml platforms: - name: instance - image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" - command: ${MOLECULE_DOCKER_COMMAND:-""} - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro + image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest privileged: true + command: /sbin/init + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host pre_build_image: true provisioner: name: ansible - lint: - name: ansible-lint playbooks: - converge: ${MOLECULE_PLAYBOOK:-playbook.yml} + converge: playbook.yml scenario: name: default verifier: - name: testinfra - lint: - name: flake8 + name: ansible diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index c99558da..a703571c 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -5,9 +5,13 @@ pre_tasks: - name: Update apt cache. - apt: update_cache=true cache_valid_time=600 + ansible.builtin.apt: + update_cache: "true" + cache_valid_time: "600" when: ansible_os_family == 'Debian' changed_when: false - roles: - - role: geerlingguy.java + tasks: + - name: Run the role + ansible.builtin.include_role: + name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}" diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 00000000..ae15672e --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,13 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Run java + ansible.builtin.command: java -version + register: java_version + changed_when: false + + - name: Assert OpenJDK is installed + ansible.builtin.assert: + that: + - "'openjdk' in java_version.stderr | lower" diff --git a/tasks/main.yml b/tasks/main.yml index c4f106f7..15a594c1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,47 +1,48 @@ --- - name: Include OS-specific variables for Fedora or FreeBSD. - include_vars: "{{ ansible_distribution }}.yml" + ansible.builtin.include_vars: "{{ ansible_distribution }}.yml" when: ansible_distribution == 'FreeBSD' or ansible_distribution == 'Fedora' - name: Include version-specific variables for CentOS/RHEL. - include_vars: "RedHat-{{ ansible_distribution_version.split('.')[0] }}.yml" - when: ansible_distribution == 'CentOS' or - ansible_distribution == 'Red Hat Enterprise Linux' or - ansible_distribution == 'RedHat' + ansible.builtin.include_vars: "RedHat-{{ ansible_distribution_version.split('.')[0] }}.yml" + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'RedHat' - name: Include version-specific variables for Ubuntu. - include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml" when: ansible_distribution == 'Ubuntu' - name: Include version-specific variables for Debian. - include_vars: "{{ ansible_distribution|title }}-{{ ansible_distribution_version.split('.')[0] }}.yml" + ansible.builtin.include_vars: "{{ ansible_distribution | title }}-{{ ansible_distribution_version.split('.')[0] }}.yml" when: ansible_os_family == 'Debian' - name: Define java_packages. - set_fact: + ansible.builtin.set_fact: java_packages: "{{ __java_packages | list }}" when: java_packages is not defined # Setup/install tasks. -- include_tasks: setup-RedHat.yml +- name: Install Java on RedHat + ansible.builtin.include_tasks: setup-RedHat.yml when: ansible_os_family == 'RedHat' -- include_tasks: setup-Debian.yml +- name: Install Java on Debian + ansible.builtin.include_tasks: setup-Debian.yml when: ansible_os_family == 'Debian' -- include_tasks: setup-FreeBSD.yml +- name: Install Java on FreeBSD + ansible.builtin.include_tasks: setup-FreeBSD.yml when: ansible_os_family == 'FreeBSD' # Environment setup. - name: Set JAVA_HOME if configured. - template: + ansible.builtin.template: src: java_home.sh.j2 dest: /etc/profile.d/java_home.sh - mode: 0644 + mode: "0644" when: java_home is defined and java_home | length > 0 - name: Set the default Java - alternatives: + community.general.alternatives: name: java path: "{{ java_home }}/bin/java" when: java_home is defined and java_home | length > 0 and java_set_default diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index 1d490c3d..fa64cd75 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -2,7 +2,7 @@ # See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199 and # https://github.com/geerlingguy/ansible-role-java/issues/64 - name: Ensure 'man' directory exists. - file: + ansible.builtin.file: path: /usr/share/man/man1 state: directory recurse: true @@ -11,26 +11,26 @@ - ansible_distribution_version is version("18.04", ">=") - name: Add Java 11 Repository for ubuntu 16.04 - become: yes + become: true become_user: root - apt_repository: - repo: 'ppa:openjdk-r/ppa' + ansible.builtin.apt_repository: + repo: "ppa:openjdk-r/ppa" state: present when: - ansible_distribution == 'Ubuntu' - ansible_distribution_version == '16.04' register: openjdk11repo -- name: Update and upgrade apt packages for ubuntu 16.04 +- name: Update and upgrade apt packages for ubuntu 16.04 # noqa: no-handler become: true become_user: root - apt: - upgrade: yes - update_cache: yes + ansible.builtin.apt: + upgrade: true + update_cache: true when: openjdk11repo.changed - name: Ensure Java is installed. - apt: + ansible.builtin.apt: name: "{{ java_packages }}" state: present - update_cache: yes + update_cache: true diff --git a/tasks/setup-FreeBSD.yml b/tasks/setup-FreeBSD.yml index ba668728..b05ae88b 100644 --- a/tasks/setup-FreeBSD.yml +++ b/tasks/setup-FreeBSD.yml @@ -1,11 +1,21 @@ --- - name: Ensure Java is installed. - pkgng: + community.general.pkgng: name: "{{ java_packages }}" state: present -- name: ensure proc is mounted - mount: name=/proc fstype=procfs src=proc opts=rw state=mounted +- name: Ensure proc is mounted + ansible.posix.mount: + name: /proc + fstype: procfs + src: proc + opts: rw + state: mounted -- name: ensure fdesc is mounted - mount: name=/dev/fd fstype=fdescfs src=fdesc opts=rw state=mounted +- name: Ensure fdesc is mounted + ansible.posix.mount: + name: /dev/fd + fstype: fdescfs + src: fdesc + opts: rw + state: mounted diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml index 13069452..9d4f515d 100644 --- a/tasks/setup-RedHat.yml +++ b/tasks/setup-RedHat.yml @@ -1,5 +1,5 @@ --- - name: Ensure Java is installed. - package: + ansible.builtin.package: name: "{{ java_packages }}" state: present diff --git a/vars/Ubuntu-24.yml b/vars/Ubuntu-24.yml new file mode 100644 index 00000000..be7415ba --- /dev/null +++ b/vars/Ubuntu-24.yml @@ -0,0 +1,8 @@ +--- +# JDK version options include: +# - java +# - openjdk-11-jdk +# - openjdk-17-jdk +# - openjdk-21-jdk +__java_packages: + - openjdk-11-jdk