diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..478f980 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,9 @@ +--- +# .ansible-lint + +exclude_paths: + - .github + - .pre-commit-config.yaml + +skip_list: + - '106' # Role name {} does not match ``^[a-z][a-z0-9_]+$`` pattern' diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e990643 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +# Change these settings to your own preference +indent_size = 2 +indent_style = space + +# We recommend you to keep these unchanged +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3988faa --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +--- +name: Release to Galaxy + +on: + push: + tags: + - '*' + +jobs: + release: + + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -q ansible + + - name: Import role into Ansible Galaxy + run: ansible-galaxy role import --api-key ${GALAXY_API_KEY} $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) + env: + GALAXY_API_KEY: ${{ secrets.GALAXY_API_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4be3c60 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,47 @@ +--- +name: Test ansible role + +on: + pull_request: + push: + branches: + - master + schedule: + - cron: "22 2 * * 2" + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3 + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Remove pre-installed ansible + run: sudo apt-get remove --purge -y ansible + + - name: Install dependencies + run: pip install ansible ansible-lint docker molecule molecule-plugins[docker] pytest-testinfra + + - name: Display versions + run: | + python -c "import sys; print(sys.version)" + pip --version + ansible --version + molecule --version + + - name: Lint code + run: | + ansible-lint + black --check . + env: + PY_COLORS: "1" + + - name: Run Molecule + run: molecule test + env: + PY_COLORS: "1" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dde905f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.pyc +.cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1336a23 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..63400df --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Nicolas Boutet + +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..b7179ef --- /dev/null +++ b/Readme.md @@ -0,0 +1,57 @@ +[![tests](https://github.com/boutetnico/ansible-role-percona-release/workflows/Test%20ansible%20role/badge.svg)](https://github.com/boutetnico/ansible-role-percona-release/actions?query=workflow%3A%22Test+ansible+role%22) +[![Ansible Galaxy](https://img.shields.io/badge/galaxy-boutetnico.percona_release-blue.svg)](https://galaxy.ansible.com/boutetnico/percona_release) + +ansible-role-percona-release +============================ + +This role installs and configures [percona-release](https://docs.percona.com/percona-software-repositories/percona-release.html). + +Requirements +------------ + +Ansible 2.10 or newer. + +Supported Platforms +------------------- + +- [Debian - 11 (Bullseye)](https://wiki.debian.org/DebianBullseye) +- [Debian - 12 (Bookworm)](https://wiki.debian.org/DebianBookworm) +- [Ubuntu - 22.04 (Jammy Jellyfish)](http://releases.ubuntu.com/22.04/) +- [Ubuntu - 24.04 (Noble Numbat)](http://releases.ubuntu.com/24.04/) + +Role Variables +-------------- + +| Variable | Required | Default | Choices | Comments | +|------------------------------|----------|---------------|-----------|---------------------------------------------------| +| percona_release_dependencies | true | `[gnupg]` | list | | +| percona_release_repositories | true | `[]` | list | Repositories to enable. | +| percona_release_version | true | `latest` | string | | + +Dependencies +------------ + +None + +Example Playbook +---------------- + + - hosts: all + roles: + - role: ansible-role-percona-release + + +Testing +------- + + molecule test + +License +------- + +MIT + +Author Information +------------------ + +[@boutetnico](https://github.com/boutetnico) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..26a1bb8 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +percona_release_dependencies: + - gnupg +percona_release_repositories: [] +percona_release_version: latest diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..2b3020c --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: Update apt cache + ansible.builtin.apt: + update_cache: true diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..dd16ec5 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,21 @@ +--- +galaxy_info: + role_name: percona_release + namespace: boutetnico + author: Nicolas Boutet + description: Install and configure percona-release. + license: MIT + min_ansible_version: "2.10" + platforms: + - name: Ubuntu + versions: + - jammy + - noble + - name: Debian + versions: + - bookworm + - bullseye + galaxy_tags: + - percona + - release +dependencies: [] diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..71d6419 --- /dev/null +++ b/molecule/default/Dockerfile.j2 @@ -0,0 +1,19 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +{% if item.env is defined %} +{% for var, value in item.env.items() %} +{% if value %} +ENV {{ var }} {{ value }} +{% endif %} +{% endfor %} +{% endif %} + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y python3 sudo bash ca-certificates iproute2 python3-apt aptitude && apt-get clean && rm -rf /var/lib/apt/lists/* diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..0382394 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + + roles: + - role: boutetnico.percona_release + percona_release_repositories: + - ps-8x-innovation diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..4af852b --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,23 @@ +--- +dependency: + name: galaxy + enabled: false + +driver: + name: docker + +platforms: + - name: ansible-role-percona-release-debian-11 + image: debian:11 + - name: ansible-role-percona-release-debian-12 + image: debian:12 + - name: ansible-role-percona-release-ubuntu-2204 + image: ubuntu:22.04 + - name: ansible-role-percona-release-ubuntu-2404 + image: ubuntu:24.04 + +provisioner: + name: ansible + +verifier: + name: testinfra diff --git a/molecule/default/tests/test_role.py b/molecule/default/tests/test_role.py new file mode 100644 index 0000000..b46b397 --- /dev/null +++ b/molecule/default/tests/test_role.py @@ -0,0 +1,24 @@ +import pytest + + +@pytest.mark.parametrize( + "name", + [ + ("percona-release"), + ], +) +def test_packages_are_installed(host, name): + package = host.package(name) + assert package.is_installed + + +@pytest.mark.parametrize( + "name", + [ + ("ps-8x-innovation"), + ], +) +def test_repositories(host, name): + command = "/usr/bin/percona-release show" + repositories_list = host.check_output(command) + assert name in repositories_list diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..997fa7f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,29 @@ +--- +- name: Ensure dependencies are installed + ansible.builtin.apt: + name: "{{ percona_release_dependencies }}" + state: present + update_cache: true + +- name: Install percona release + ansible.builtin.apt: + deb: "https://repo.percona.com/apt/percona-release_{{ percona_release_version }}.{{ ansible_distribution_release }}_all.deb" + state: present + environment: + PERCONA_TELEMETRY_DISABLE: "1" + notify: Update apt cache + +- name: Check if Percona repository is already enabled + ansible.builtin.command: "percona-release show" + changed_when: false + register: percona_release_show + +- name: Enable Percona repository + ansible.builtin.command: "percona-release enable {{ item }} release" + changed_when: false + loop: "{{ percona_release_repositories }}" + when: item not in percona_release_show.stdout + notify: Update apt cache + +- name: Ensure apt cache is updated now if needed + ansible.builtin.meta: "flush_handlers"