Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
boutetnico committed Aug 2, 2024
0 parents commit a230e92
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -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'
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
*.pyc
.cache
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
57 changes: 57 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
percona_release_dependencies:
- gnupg
percona_release_repositories: []
percona_release_version: latest
4 changes: 4 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
21 changes: 21 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -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: []
19 changes: 19 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -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/*
8 changes: 8 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Converge
hosts: all

roles:
- role: boutetnico.percona_release
percona_release_repositories:
- ps-8x-innovation
23 changes: 23 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions molecule/default/tests/test_role.py
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a230e92

Please sign in to comment.