From ff6a86b312a733a020b89037434bf3a0effcd2b9 Mon Sep 17 00:00:00 2001 From: pwalczysko Date: Tue, 7 Oct 2025 16:53:57 +0100 Subject: [PATCH 1/2] Update framework --- .github/workflows/molecule.yml | 18 +++++++++--------- meta/main.yml | 4 ++-- molecule/default/Dockerfile.j2 | 22 ---------------------- molecule/default/molecule.yml | 9 +++++++-- molecule/default/playbook.yml | 5 ++++- molecule/default/tests/test_default.py | 4 ++-- tasks/main.yml | 21 ++++++++++++++++++++- 7 files changed, 44 insertions(+), 39 deletions(-) delete mode 100644 molecule/default/Dockerfile.j2 diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index a247bd70..31b520f0 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -10,11 +10,11 @@ on: jobs: list-scenarios: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 outputs: matrix: ${{ steps.listscenarios.outputs.scenarios }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - id: listscenarios uses: ome/action-ansible-molecule-list-scenarios@main @@ -22,21 +22,21 @@ jobs: name: Test needs: - list-scenarios - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: # Keep running so we can see if other tests pass fail-fast: false matrix: scenario: ${{fromJson(needs.list-scenarios.outputs.matrix)}} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.12' - name: Install Ansible & Molecule run: | - pip install "ansible<8" "ansible-lint<6.13" flake8 - pip install "molecule<5" "ansible-compat<4" + pip install "requests" "ansible" "ansible-lint" "flake8" + pip install "molecule" "ansible-compat" pip install molecule-plugins[docker] pytest-testinfra - name: Run molecule run: molecule test -s "${{ matrix.scenario }}" @@ -46,7 +46,7 @@ jobs: if: startsWith(github.ref, 'refs/tags') needs: - test - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - name: galaxy uses: ome/action-ansible-galaxy-publish@main diff --git a/meta/main.yml b/meta/main.yml index 844a9cc9..90735e45 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -8,11 +8,11 @@ galaxy_info: description: HAProxy installation and configuration. company: Open Microscopy Environment license: "license (BSD, MIT)" - min_ansible_version: 2.3 + min_ansible_version: 2.11 platforms: - name: EL versions: - - 7 + - 9 namespace: ome galaxy_tags: - web diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 deleted file mode 100644 index 2609f519..00000000 --- a/molecule/default/Dockerfile.j2 +++ /dev/null @@ -1,22 +0,0 @@ -# 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 %} - -RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates iproute2 python-apt aptitude && apt-get clean; \ - elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute && dnf clean all; \ - elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute ca-certificates && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ - elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \ - elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ - elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 38e726c9..8d6b94a7 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -8,11 +8,16 @@ lint: | ansible-lint flake8 platforms: - - name: haproxy-c7 - image: centos/systemd + - name: haproxy-u2204 + image: eniocarboni/docker-ubuntu-systemd:22.04 image_version: latest command: /sbin/init privileged: true + cgroupns_mode: host + tmpfs: + - /sys/fs/cgroup + groups: + - extra_options provisioner: name: ansible lint: diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index eb4d7ab6..676c3a73 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -3,12 +3,15 @@ hosts: all pre_tasks: - name: Install dependencies - package: + become: true + ansible.builtin.apt: + update_cache: true name: - curl - rsyslog - openssl state: present + - name: Ensure dummy certificate is in place command: >- openssl req -x509 -nodes -days 365 -newkey rsa:2048 diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 7f9c8173..8cc45c5e 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -9,14 +9,14 @@ def test_service_running_and_enabled(host,): - if host.file('/etc/redhat-release').exists: + if host.file('/etc/os-release').exists: service = host.service('haproxy') assert service.is_running assert service.is_enabled else: # BUG: testinfra tries to use systemd out = host.check_output('service haproxy status') - assert out == 'haproxy is running.' + assert out == 'Active: active (running)' @pytest.mark.parametrize('name', [ diff --git a/tasks/main.yml b/tasks/main.yml index e360ed01..6d635eea 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,9 @@ --- + - name: Ensure HAProxy is installed become: true - package: + ansible.builtin.apt: + update_cache: true name: "{{ haproxy_package_name }}" state: present @@ -59,3 +61,20 @@ - name: Ensure HAProxy is started and enabled on boot. become: true service: name=haproxy state=started enabled=yes + +# - name: restart haproxy +# become: true +# service: +# name: haproxy +# state: restarted + +# - name: Debug output of systemclt rsyslog +# become: true +# ansible.builtin.command: +# systemctl status haproxy +# register: haproxy_status +# ignore_errors: yes + +# - name: Show output +# debug: +# msg: "{{ haproxy_status.stdout }}" \ No newline at end of file From 46ba0935d021ec1aeac8a2780ae6171dacbf187b Mon Sep 17 00:00:00 2001 From: pwalczysko Date: Mon, 27 Oct 2025 11:27:43 +0000 Subject: [PATCH 2/2] Implement update_cache plan --- molecule/default/playbook.yml | 1 + tasks/main.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml index 676c3a73..150787b9 100644 --- a/molecule/default/playbook.yml +++ b/molecule/default/playbook.yml @@ -6,6 +6,7 @@ become: true ansible.builtin.apt: update_cache: true + cache_valid_time: 86400 name: - curl - rsyslog diff --git a/tasks/main.yml b/tasks/main.yml index 6d635eea..1568d14c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,6 +4,7 @@ become: true ansible.builtin.apt: update_cache: true + cache_valid_time: 86400 name: "{{ haproxy_package_name }}" state: present