Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hifis.redis role #237

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ netplan:
- "roles/netplan/**"
- "molecule/netplan/**"
- ".github/workflows/netplan.yml"
redis:
- changed-files:
- any-glob-to-any-file:
- "roles/redis/**"
- "molecule/redis/**"
- ".github/workflows/redis.yml"
ssh_keys:
- changed-files:
- any-glob-to-any-file:
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
name: "hifis.toolkit.redis"

on:
pull_request:
paths:
- '.github/workflows/redis.yml'
- 'roles/redis/**'
- 'molecule/redis/**'
- 'Pipfile'
- 'Pipfile.lock'
push:
branches:
- "main"
tags:
- "v*.*.*"
paths:
- '.github/workflows/redis.yml'
- 'roles/redis/**'
- 'molecule/redis/**'
- 'Pipfile'
- 'Pipfile.lock'
schedule:
- cron: "0 0 * * *"
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1

jobs:

test:
name: "Run Molecule tests."
runs-on: "ubuntu-24.04"
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
strategy:
fail-fast: false
matrix:
image:
- "ghcr.io/hifis-net/ubuntu-systemd:20.04"
- "ghcr.io/hifis-net/ubuntu-systemd:22.04"

steps:
- name: "Check out the codebase."
uses: "actions/checkout@v4"
with:
path: "ansible_collections/hifis/toolkit"

- name: "Prepare the job environment."
uses: "./ansible_collections/hifis/toolkit/.github/workflows/prepare-action"

# https://github.com/ansible/molecule/issues/3806
- name: "Help molecule to find the dependencies"
run: |
mkdir -p /home/runner/.ansible
ln -s /home/runner/work/ansible-collection-toolkit/ansible-collection-toolkit/ansible_collections/hifis/toolkit/roles \
/home/runner/.ansible/roles

- name: "Run Molecule tests."
run: "pipenv run molecule test -s redis"
env:
MOLECULE_IMAGE: "${{ matrix.image }}"
working-directory: "ansible_collections/hifis/toolkit"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ software engineers, but not exclusively. The following use cases are supported:
* DevOps platform:
* [GitLab](https://github.com/hifis-net/ansible-role-gitlab) (**coming soon!**)
* deploy [**GitLab-Runner**](roles/gitlab_runner) with a focus, but not limited, on Openstack autoscaling
* [Redis](https://github.com/hifis-net/ansible-role-redis) (**coming soon!**)
* [**Redis**](role/redis)
Normo marked this conversation as resolved.
Show resolved Hide resolved
* Help desk:
* [**Zammad**](roles/zammad)
* High Availability (HA) / Load Balancing:
Expand Down
14 changes: 14 additions & 0 deletions molecule/redis/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
- name: "Converge"
hosts: "all"
tasks:
- name: "Include redis_role"
ansible.builtin.include_role:
name: "hifis.toolkit.redis"

...
48 changes: 48 additions & 0 deletions molecule/redis/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
dependency:
name: "galaxy"
driver:
name: "podman"
platforms:
- name: "instance_redis"
image: "${MOLECULE_IMAGE:-ghcr.io/hifis-net/ubuntu-systemd:22.04}"
pre_build_image: true
privileged: true
systemd: "always"
tty: true
override_command: false
provisioner:
name: "ansible"
config_options:
defaults:
stdout_callback: "yaml"
playbooks:
prepare: "prepare.yml"
converge: "converge.yml"
inventory:
hosts:
all:
vars:
redis_sentinel_password: "123456"
verifier:
name: "ansible"
scenario:
name: "redis"
test_sequence:
- "destroy"
- "syntax"
- "create"
- "prepare"
- "check"
- "converge"
- "idempotence"
- "check"
- "verify"
- "destroy"

...
21 changes: 21 additions & 0 deletions molecule/redis/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
- name: "Prepare"
hosts: "all"
tasks:
- name: "Install dependencies"
ansible.builtin.apt:
name:
- "ca-certificates" # for Redis download
- "iproute2" # for gathering network facts
- "net-tools" # for gathering listening ports
- "python3-redis" # required by community.general.redis
- "sudo" # for `become` privilege escalation
update_cache: true
state: "present"

...
53 changes: 53 additions & 0 deletions molecule/redis/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: Helmholtz Centre for Environmental Research (UFZ)
# SPDX-FileCopyrightText: Helmholtz-Zentrum Dresden-Rossendorf (HZDR)
#
# SPDX-License-Identifier: Apache-2.0

---
- name: "Verify"
hosts: "all"
vars:
redis_server_service_name: "redis-server"
redis_sentinel_service_name: "redis-sentinel"
redis_server_port: 6379
redis_sentinel_port: 26379
redis_ports:
- "{{ redis_server_port }}"
- "{{ redis_sentinel_port }}"
redis_password: "changeme"
tasks:
- name: "Populate service facts"
ansible.builtin.service_facts:
register: "services_state"

- name: "Check that Redis is running on instance"
ansible.builtin.assert:
that:
- "services_state.ansible_facts.services[redis_server_service_name + '.service'].state is search('running')"
- "services_state.ansible_facts.services[redis_sentinel_service_name + '.service'].state is search('running')"

- name: "Gather facts on listening ports."
community.general.listen_ports_facts:

- name: "Check if Redis is listening on TCP ports"
vars:
tcp_listen: "{{ ansible_facts.tcp_listen | selectattr('port', 'in', redis_ports) | list }}"
ansible.builtin.assert:
that:
- "item.name == redis_server_service_name"
loop: "{{ tcp_listen }}"

- name: "Ensure Redis is in master mode"
community.general.redis:
command: "slave"
slave_mode: "master"
login_password: "{{ redis_password }}"

- name: "Configure Redis maxmemory"
community.general.redis:
command: "config"
name: "maxmemory"
value: "0"
login_password: "{{ redis_password }}"

...
Loading