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

fix: remove EOL platforms for current ones #395

Merged
merged 13 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
106 changes: 106 additions & 0 deletions .config/molecule/alternative/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
- name: Run local preparation
hosts: localhost
gather_facts: false
vars:
__role_name: "{{ lookup('ansible.builtin.env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
__binary_name: "{{ __role_name }}"
__binary_url: "{{ lookup('ansible.builtin.vars', __role_name ~ '_binary_url', default='') }}"
__binary_local_dir: "{{ lookup('ansible.builtin.vars', __role_name ~ '_binary_local_dir', default='') }}"
__tls_server_config: "{{ lookup('ansible.builtin.vars', __role_name ~ '_tls_server_config', default={}) }}"
tasks:
- name: "Create local binary directory"
ansible.builtin.file:
path: "{{ __binary_local_dir }}"
state: directory
mode: 0755
when: (__binary_local_dir)

- name: "Fetch binary"
become: false
ansible.builtin.unarchive:
src: "{{ __binary_url }}"
dest: "{{ __binary_local_dir }}"
remote_src: true
list_files: true
extra_opts:
- "--strip-components=1"
creates: "{{ __binary_local_dir }}/{{ __binary_name }}"
check_mode: false
register: __download_binary
when: (__binary_url)

- name: Generate self signed certificates
when: "'cert_file' in __tls_server_config"
block:
- name: Install pyOpenSSL for certificate generation
ansible.builtin.pip:
name: "pyOpenSSL"

- name: Create private key
community.crypto.openssl_privatekey:
path: "/tmp/tls.key"

- name: Create CSR
community.crypto.openssl_csr:
path: "/tmp/tls.csr"
privatekey_path: "/tmp/tls.key"

- name: Create certificate
community.crypto.x509_certificate:
path: "/tmp/tls.cert"
csr_path: "/tmp/tls.csr"
privatekey_path: "/tmp/tls.key"
provider: selfsigned

- name: Filter out incompatible distro/ansible version combos
ansible.builtin.add_host:
name: "{{ item }}"
groups: target_hosts
loop: >-
{{
groups['all']
| map('extract', hostvars)
| rejectattr('exclude_ansible_vers', 'defined')
| map(attribute='inventory_hostname')
| list
| union(
groups['all']
| map('extract', hostvars)
| selectattr('exclude_ansible_vers', 'defined')
| rejectattr('exclude_ansible_vers', 'search', ansible_version.major ~ '.' ~ ansible_version.minor)
| map(attribute='inventory_hostname')
| list
)
}}
when: item not in groups['target_hosts']
changed_when: false

- name: Run target preparation
hosts: target_hosts
any_errors_fatal: true
vars:
__role_name: "{{ lookup('ansible.builtin.env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
__tls_server_config: "{{ lookup('ansible.builtin.vars', __role_name ~ '_tls_server_config', default={}) }}"
tasks:
- name: Copy self signed certificates
when: "'cert_file' in __tls_server_config"
block:
- name: "Create cert dir"
ansible.builtin.file:
path: "{{ __tls_server_config.cert_file | dirname }}"
state: directory
owner: root
group: root
mode: u+rwX,g+rwX,o=rX

- name: "Copy cert and key"
ansible.builtin.copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode | default('0644') }}"
loop:
- src: "/tmp/tls.cert"
dest: "{{ __tls_server_config.cert_file }}"
- src: "/tmp/tls.key"
dest: "{{ __tls_server_config.key_file }}"
50 changes: 34 additions & 16 deletions .config/molecule/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,26 @@ platforms:
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: centos-7
image: dokken/centos-7
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /usr/lib/systemd/systemd
- name: centos-stream-9
image: dokken/centos-stream-9
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: debian-10
image: dokken/debian-10
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: debian-11
image: dokken/debian-11
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: fedora-37
image: dokken/fedora-37
- name: fedora-39
image: dokken/fedora-39
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: fedora-38
image: dokken/fedora-38
- name: fedora-40
image: dokken/fedora-40
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
Expand All @@ -65,8 +53,38 @@ platforms:
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
- name: ubuntu-24.04
image: dokken/ubuntu-24.04
pre_build_image: true
privileged: true
cgroup_parent: docker.slice
command: /lib/systemd/systemd
verifier:
name: testinfra
additional_files_or_dirs:
- "../../../../../.testinfra/testinfra_helpers.py"
env:
PYTHONPATH: "${MOLECULE_PROJECT_DIRECTORY}/../../.testinfra:${PYTHONPATH}"
provisioner:
playbooks:
converge: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/converge.yml"
inventory:
hosts:
target_hosts:
hosts: {}
host_vars:
fedora-39:
exclude_ansible_vers:
- "2.9"
- "2.10"
- "2.11"
fedora-40:
exclude_ansible_vers:
- "2.9"
- "2.10"
- "2.11"
ubuntu-24.04:
exclude_ansible_vers:
- "2.9"
- "2.10"
- "2.11"
29 changes: 28 additions & 1 deletion .config/molecule/converge.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
---
- name: Filter and add hosts to ansible_compatible_hosts
hosts: localhost
gather_facts: false
tasks:
- name: Filter out incompatible distro/ansible version combos
ansible.builtin.add_host:
name: "{{ item }}"
groups: target_hosts
loop: >-
{{
groups['all']
| map('extract', hostvars)
| rejectattr('exclude_ansible_vers', 'defined')
| map(attribute='inventory_hostname')
| list
| union(
groups['all']
| map('extract', hostvars)
| selectattr('exclude_ansible_vers', 'defined')
| rejectattr('exclude_ansible_vers', 'search', ansible_version.major ~ '.' ~ ansible_version.minor)
| map(attribute='inventory_hostname')
| list
)
}}
when: item not in groups['target_hosts']
changed_when: false

- name: Converge
hosts: all
hosts: target_hosts
any_errors_fatal: true
tasks:
- name: "Run role"
Expand Down
70 changes: 70 additions & 0 deletions .testinfra/testinfra_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import testinfra


def get_ansible_version():
"""
Get the current Ansible version from localhost using the 'debug' module.

Returns:
str: The current Ansible version (major.minor).
"""
localhost = testinfra.get_host(
"ansible://localhost?ansible_inventory=localhost,"
)
local_ansible_version = localhost.ansible("debug", "var=ansible_version")
ansible_version = '.'.join(
local_ansible_version['ansible_version']['full'].split('.')[:2]
)
return ansible_version


def filter_compatible_hosts(inventory, ansible_version):
"""
Filter hosts based on Ansible version compatibility.

Args:
inventory (str): The inventory file path.
ansible_version (str): The current Ansible version (major.minor).

Returns:
list: A list of compatible hosts that do not have the current Ansible
version in their exclude_ansible_vers hostvars.
"""
ansible_runner = testinfra.utils.ansible_runner.AnsibleRunner(inventory)
all_hosts = ansible_runner.get_hosts('all')
compatible_hosts = []

for host in all_hosts:
# Get host variables
host_vars = ansible_runner.get_variables(host)

# Check if the host should be excluded
if 'exclude_ansible_vers' in host_vars:
excluded_versions = host_vars['exclude_ansible_vers']
if ansible_version in excluded_versions:
continue
compatible_hosts.append(host)

return compatible_hosts


def get_target_hosts():
"""
Get the filtered target hosts based on the current Ansible version.

Returns:
list: A list of hosts that are compatible with
the current Ansible version.
"""
# Get current Ansible version
current_ansible_version = get_ansible_version()

# Get the inventory file from environment
inventory_file = os.environ['MOLECULE_INVENTORY_FILE']

# Filter the hosts based on the exclusion criteria
return filter_compatible_hosts(inventory_file, current_ansible_version)
7 changes: 3 additions & 4 deletions roles/alertmanager/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ galaxy_info:
versions:
- "focal"
- "jammy"
- "noble"
- name: "Debian"
versions:
- "bullseye"
- "buster"
- name: "EL"
versions:
- "7"
- "8"
- "9"
- name: "Fedora"
versions:
- "37"
- '38'
- "39"
- "40"
galaxy_tags:
- "monitoring"
- "prometheus"
Expand Down
4 changes: 4 additions & 0 deletions roles/alertmanager/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
provisioner:
playbooks:
prepare: "${MOLECULE_PROJECT_DIRECTORY}/../../.config/molecule/alternative/prepare.yml"
inventory:
group_vars:
all:
Expand Down Expand Up @@ -34,3 +36,5 @@ provisioner:
- "127.0.0.1:6783"
- "alertmanager.demo.do.prometheus.io:6783"
alertmanager_version: 0.25.0
alertmanager_binary_url: "https://github.com/prometheus/alertmanager/releases/download/v{{ alertmanager_version\
\ }}/alertmanager-{{ alertmanager_version }}.linux-amd64.tar.gz"
33 changes: 0 additions & 33 deletions roles/alertmanager/molecule/alternative/prepare.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import testinfra.utils.ansible_runner
from testinfra_helpers import get_target_hosts
import pytest

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
testinfra_hosts = get_target_hosts()


@pytest.mark.parametrize("dirs", [
Expand Down
6 changes: 2 additions & 4 deletions roles/alertmanager/molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import testinfra.utils.ansible_runner
import pytest
from testinfra_helpers import get_target_hosts

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
testinfra_hosts = get_target_hosts()


@pytest.mark.parametrize("dirs", [
Expand Down
Loading
Loading