From 4ffeb9e12abc8ffe7f06b115693691895a15516a Mon Sep 17 00:00:00 2001 From: Anton Melekhin Date: Fri, 10 Nov 2023 23:10:37 +0400 Subject: [PATCH] feat: initial commit --- .ansible-lint | 2 + .github/workflows/molecule.yml | 31 +++++++++++ .github/workflows/publish.yml | 19 +++++++ .github/workflows/release.yml | 30 +++++++++++ .releaserc.yml | 94 ++++++++++++++++++++++++++++++++++ .yamllint | 33 ++++++++++++ LICENSE | 21 ++++++++ README.md | 57 +++++++++++++++++++++ defaults/main.yml | 2 + meta/main.yml | 33 ++++++++++++ molecule/default/converge.yml | 5 ++ molecule/default/molecule.yml | 23 +++++++++ molecule/default/verify.yml | 15 ++++++ tasks/configure.yml | 7 +++ tasks/install-Debian.yml | 7 +++ tasks/install-RedHat.yml | 6 +++ tasks/main.yml | 14 +++++ templates/java_home.sh.j2 | 3 ++ tox-requirements.txt | 3 ++ tox.ini | 21 ++++++++ vars/Debian-10.yml | 3 ++ vars/Debian-11.yml | 3 ++ vars/Debian-12.yml | 3 ++ vars/RedHat-7.yml | 3 ++ vars/RedHat-8.yml | 3 ++ vars/RedHat-9.yml | 3 ++ vars/Ubuntu-18.yml | 3 ++ vars/Ubuntu-20.yml | 3 ++ vars/Ubuntu-22.yml | 3 ++ 29 files changed, 453 insertions(+) create mode 100644 .ansible-lint create mode 100644 .github/workflows/molecule.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc.yml create mode 100644 .yamllint create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/verify.yml create mode 100644 tasks/configure.yml create mode 100644 tasks/install-Debian.yml create mode 100644 tasks/install-RedHat.yml create mode 100644 tasks/main.yml create mode 100644 templates/java_home.sh.j2 create mode 100644 tox-requirements.txt create mode 100644 tox.ini create mode 100644 vars/Debian-10.yml create mode 100644 vars/Debian-11.yml create mode 100644 vars/Debian-12.yml create mode 100644 vars/RedHat-7.yml create mode 100644 vars/RedHat-8.yml create mode 100644 vars/RedHat-9.yml create mode 100644 vars/Ubuntu-18.yml create mode 100644 vars/Ubuntu-20.yml create mode 100644 vars/Ubuntu-22.yml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..72277b6 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,2 @@ +skip_list: + - 'role-name' diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 0000000..dbaa297 --- /dev/null +++ b/.github/workflows/molecule.yml @@ -0,0 +1,31 @@ +--- +name: 'Molecule' +on: + pull_request: + push: + branches: + - main + +jobs: + test: + name: 'Test' + runs-on: ubuntu-latest + strategy: + matrix: + include: + - distro: 'debian-12' + - distro: 'rockylinux-9' + - distro: 'ubuntu-22.04' + + steps: + - name: 'Checkout the codebase' + uses: actions/checkout@v3 + + - name: 'Test role' + uses: gofrolist/molecule-action@v2 + with: + molecule_command: test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + TAG: ${{ matrix.distro }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7968eb3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,19 @@ +--- +name: 'Publish' +on: + release: + types: + - published + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: 'Checkout the codebase' + uses: actions/checkout@v3 + + - name: 'Publish to Ansible Galaxy' + uses: robertdebock/galaxy-action@1.2.0 + with: + galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} + git_branch: main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..077212a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +--- +name: 'Release' +on: + push: + branches: + - main + +jobs: + release: + name: 'Release' + runs-on: ubuntu-latest + # Skip running release workflow on forks + if: github.repository_owner == 'antmelekhin' + steps: + - name: 'Checkout the codebase' + uses: actions/checkout@v3 + with: + fetch-depth: 0 + persist-credentials: false + + - name: 'Semantic Release' + uses: cycjimmy/semantic-release-action@v3 + with: + semantic_version: 19.0.5 + extra_plugins: | + @semantic-release/git@10.0.1 + @semantic-release/changelog@6.0.3 + conventional-changelog-conventionalcommits@5.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.releaserc.yml b/.releaserc.yml new file mode 100644 index 0000000..de832c2 --- /dev/null +++ b/.releaserc.yml @@ -0,0 +1,94 @@ +--- +branches: ['main'] +preset: 'conventionalcommits' +ci: false + +verifyConditions: + - '@semantic-release/changelog' + - '@semantic-release/git' + - '@semantic-release/github' + +analyzeCommits: + - path: '@semantic-release/commit-analyzer' + releaseRules: + - type: 'breaking' + release: 'major' + - type: 'chore' + release: false + - type: 'ci' + release: false + - type: 'docs' + release: false + - type: 'feat' + release: 'minor' + - type: 'fix' + release: 'patch' + - type: 'improv' + release: 'minor' + - type: 'refactor' + release: 'patch' + - type: 'revert' + release: 'patch' + - type: 'style' + release: false + - type: 'test' + release: false + +generateNotes: + - path: '@semantic-release/release-notes-generator' + writerOpts: + groupBy: 'type' + commitGroupsSort: 'title' + commitsSort: 'header' + linkCompare: true + linkReferences: true + presetConfig: + types: + - type: 'breaking' + section: 'Breaking changes!' + hidden: false + - type: 'chore' + section: 'Miscellaneous Chores' + hidden: true + - type: 'ci' + section: 'Continuous Integration' + hidden: false + - type: 'docs' + section: 'Documentation' + hidden: false + - type: 'feat' + section: 'Features' + hidden: false + - type: 'fix' + section: 'Fixes' + hidden: false + - type: 'improv' + section: 'Improvements' + hidden: false + - type: 'refactor' + section: 'Code Refactoring' + hidden: false + - type: 'revert' + section: 'Reverts' + hidden: false + - type: 'style' + section: 'Styles' + hidden: false + - type: 'test' + section: 'Tests' + hidden: false + +prepare: + - path: '@semantic-release/changelog' + changelogFile: 'CHANGELOG.md' + changelogTitle: '# Changelog' + - path: '@semantic-release/git' + assets: ['CHANGELOG.md'] + message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + +publish: + - path: '@semantic-release/github' + +success: false + +fail: false diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6e0394d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Anton Melekhin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f2a606 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +Java +==== + +An Ansible role for install Java. + +Requirements +------------ + +- Supported version of Ansible: 2.12 and highter. +- Supported platforms: + - Debian + - 10 + - 11 + - 12 + - RHEL + - 7 + - 8 + - 9 + - Ubuntu + - 18.04 + - 20.04 + - 22.04 + +Role Variables +-------------- + +- `java_packages` List of `Java` packages (see default values in `vars/*.yml`). + +Dependencies +------------ + +None. + +Example Playbook +---------------- + +- Install `Java` package: + + ```yaml + --- + + - name: 'Install Java package' + hosts: all + + roles: + - role: antmelekhin.java + ``` + +License +------- + +MIT + +Author Information +------------------ + +Melekhin Anton. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..56e1a27 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +java_packages: '{{ _java_packages }}' diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..7fedb2c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,33 @@ +--- +galaxy_info: + author: antmelekhin + role_name: java + description: An Ansible role for install Java. + + license: MIT + + min_ansible_version: '2.12' + + platforms: + - name: Debian + versions: + - 'buster' + - 'bullseye' + - 'bookworm' + - name: EL + versions: + - '7' + - '8' + - '9' + - name: Ubuntu + versions: + - 'bionic' + - 'focal' + - 'jammy' + + galaxy_tags: + - 'openjdk' + - 'java' + - 'jdk' + +dependencies: [] diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..7fe1e88 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: antmelekhin.java diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..0552230 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,23 @@ +--- +dependency: + name: galaxy + enabled: true +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint +platforms: + - name: '${IMAGE:-docker-systemd}-${TAG:-ubuntu-22.04}${TOX_ENVNAME}' + image: '${NAMESPACE:-antmelekhin}/${IMAGE:-docker-systemd}:${TAG:-ubuntu-22.04}' + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + - /var/lib/containerd + cgroupns_mode: host + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..10f1fae --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,15 @@ +--- +- name: 'Verify' + hosts: all + gather_facts: false + + tasks: + - name: 'Check current Java version' + ansible.builtin.command: + cmd: java --version + changed_when: false + register: _java_version_check + + - name: 'Java version output' + ansible.builtin.debug: + msg: '{{ _java_version_check.stdout }}' diff --git a/tasks/configure.yml b/tasks/configure.yml new file mode 100644 index 0000000..27c1ee1 --- /dev/null +++ b/tasks/configure.yml @@ -0,0 +1,7 @@ +--- +- name: 'Set JAVA_HOME if configured' + ansible.builtin.template: + src: 'java_home.sh.j2' + dest: '/etc/profile.d/java_home.sh' + mode: 0755 + when: java_home is defined and java_home diff --git a/tasks/install-Debian.yml b/tasks/install-Debian.yml new file mode 100644 index 0000000..7717462 --- /dev/null +++ b/tasks/install-Debian.yml @@ -0,0 +1,7 @@ +--- +- name: 'Install Java packages' + ansible.builtin.apt: + name: '{{ java_packages }}' + update_cache: true + state: present + become: true diff --git a/tasks/install-RedHat.yml b/tasks/install-RedHat.yml new file mode 100644 index 0000000..1519862 --- /dev/null +++ b/tasks/install-RedHat.yml @@ -0,0 +1,6 @@ +--- +- name: 'Install Java packages' + ansible.builtin.package: + name: '{{ java_packages }}' + state: present + become: true diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ea1f299 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,14 @@ +--- +- name: 'Include OS-specific variables' + ansible.builtin.include_vars: '{{ distribution }}' + with_first_found: + - '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml' + - '{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml' + loop_control: + loop_var: distribution + +- name: 'Include OS-specific tasks for install packages' + ansible.builtin.include_tasks: 'install-{{ ansible_os_family }}.yml' + +- name: 'Include tasks for configure Java' + ansible.builtin.import_tasks: 'configure.yml' diff --git a/templates/java_home.sh.j2 b/templates/java_home.sh.j2 new file mode 100644 index 0000000..7b6a73b --- /dev/null +++ b/templates/java_home.sh.j2 @@ -0,0 +1,3 @@ +{{ ansible_managed | comment }} +export JAVA_HOME={{ java_home }} +export PATH=$JAVA_HOME/bin:$PATH \ No newline at end of file diff --git a/tox-requirements.txt b/tox-requirements.txt new file mode 100644 index 0000000..47cd6dc --- /dev/null +++ b/tox-requirements.txt @@ -0,0 +1,3 @@ +ansible-lint == 6.* +molecule == 5.* +molecule-plugins[docker] == 23.* \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..eb20ba2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,21 @@ +[tox] +min_version = 4.0 +env_list = ansible{7,8} + +[testenv] +deps = + -rtox-requirements.txt + ansible7: ansible == 7.* + ansible8: ansible == 8.* + +commands = molecule test + +setenv = + PY_COLORS=1 + ANSIBLE_FORCE_COLOR=1 + TOX_ENVNAME=-{envname} + +passenv = + NAMESPACE + IMAGE + TAG \ No newline at end of file diff --git a/vars/Debian-10.yml b/vars/Debian-10.yml new file mode 100644 index 0000000..844a315 --- /dev/null +++ b/vars/Debian-10.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-11-jdk diff --git a/vars/Debian-11.yml b/vars/Debian-11.yml new file mode 100644 index 0000000..844a315 --- /dev/null +++ b/vars/Debian-11.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-11-jdk diff --git a/vars/Debian-12.yml b/vars/Debian-12.yml new file mode 100644 index 0000000..e1e9a0e --- /dev/null +++ b/vars/Debian-12.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-17-jdk diff --git a/vars/RedHat-7.yml b/vars/RedHat-7.yml new file mode 100644 index 0000000..fa6955e --- /dev/null +++ b/vars/RedHat-7.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - java-1.8.0-openjdk diff --git a/vars/RedHat-8.yml b/vars/RedHat-8.yml new file mode 100644 index 0000000..35e5fdd --- /dev/null +++ b/vars/RedHat-8.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - java-11-openjdk diff --git a/vars/RedHat-9.yml b/vars/RedHat-9.yml new file mode 100644 index 0000000..d7b8ffa --- /dev/null +++ b/vars/RedHat-9.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - java-17-openjdk diff --git a/vars/Ubuntu-18.yml b/vars/Ubuntu-18.yml new file mode 100644 index 0000000..844a315 --- /dev/null +++ b/vars/Ubuntu-18.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-11-jdk diff --git a/vars/Ubuntu-20.yml b/vars/Ubuntu-20.yml new file mode 100644 index 0000000..844a315 --- /dev/null +++ b/vars/Ubuntu-20.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-11-jdk diff --git a/vars/Ubuntu-22.yml b/vars/Ubuntu-22.yml new file mode 100644 index 0000000..e1e9a0e --- /dev/null +++ b/vars/Ubuntu-22.yml @@ -0,0 +1,3 @@ +--- +_java_packages: + - openjdk-17-jdk