add curl_scheduled role

This commit is contained in:
Sergey Malyuk
2025-12-16 12:24:14 +03:00
parent 64197142db
commit 400834cc3b
21 changed files with 365 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
---
- name: Converge
hosts: all
pre_tasks:
- name: "Create test directory"
ansible.builtin.file:
path: "/test"
state: directory
mode: "0664"
- name: "Create a test file"
ansible.builtin.lineinfile:
path: "/test/index.html"
create: true
mode: "0664"
line: "OK"
- name: "Simulate remote HTTP server(s) directly on localhost"
changed_when: false
async: 1
poll: 0
args:
chdir: "/test"
loop:
- 8080
- 8081
- 8082
ansible.builtin.shell:
cmd: nohup python3 -m http.server {{ item }} </dev/null >/dev/null 2>&1 &
executable: /bin/bash
roles:
- role: genlab.curl_scheduled
services:
- label: "localhost-test-zero"
url: "http://127.0.0.1:8080"
schedule: minutely
- label: "localhost-test-one"
url: "http://127.0.0.1:8081"
schedule: hourly
- label: "localhost-test-chained-curl"
curl_cmd: '/usr/bin/curl "http://127.0.0.1:8081" && /usr/bin/curl'
url: "http://127.0.0.1:8082"
schedule: minutely

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2404}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,81 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
# Verify the systemd timers
- name: "Check the timer status - localhost-test-zero"
register: timer_zero
ansible.builtin.systemd:
name: "curl-localhost-test-zero.timer"
- name: "Assert that the localhost-test-zero timer is running"
ansible.builtin.assert:
that:
- timer_zero.status.ActiveState == "active"
success_msg: "Timer is running"
fail_msg: "Unexpected timer state: '{{ timer_zero.status.ActiveState }}'"
- name: "Check the timer status - localhost-test-one"
register: timer_one
ansible.builtin.systemd:
name: "curl-localhost-test-one.timer"
- name: "Assert that the localhost-test-one timer is running"
ansible.builtin.assert:
that:
- timer_one.status.ActiveState == "active"
success_msg: "Timer is running"
fail_msg: "Unexpected timer state: '{{ timer_one.status.ActiveState }}'"
- name: "Check the timer status - localhost-test-chained-curl"
register: timer_chained_curl
ansible.builtin.systemd:
name: "curl-localhost-test-chained-curl.timer"
- name: "Assert that the localhost-test-chained-curl timer is running"
ansible.builtin.assert:
that:
- timer_chained_curl.status.ActiveState == "active"
success_msg: "Timer is running"
fail_msg: "Unexpected timer state: '{{ timer_chained_curl.status.ActiveState }}'"
## Verify the systemd services
- name: "Check the service status - zero"
register: service_zero
ansible.builtin.systemd:
name: "curl-localhost-test-zero.service"
- name: "Assert that the localhost-test-zero service exited with a 0/SUCCESS status"
ansible.builtin.assert:
that:
- 'service_zero.status.ExecMainStatus == "0"'
success_msg: "Service has exited with a 0/SUCCESS status"
fail_msg: "Unexpected service status code: '{{ service_zero.status.ExecMainStatus }}'"
- name: "Check the service status - one"
register: service_one
ansible.builtin.systemd:
name: "curl-localhost-test-one.service"
- name: "Assert that the localhost-test-one service exited with a 0/SUCCESS status"
ansible.builtin.assert:
that:
- 'service_one.status.ExecMainStatus == "0"'
success_msg: "Service has exited with a 0/SUCCESS status"
fail_msg: "Unexpected service status code: '{{ service_one.status.ExecMainStatus }}'"
- name: "Check the service status - localhost-test-chained-curl"
register: service_chained_curl
ansible.builtin.systemd:
name: "curl-localhost-test-chained-curl.service"
- name: "Assert that the localhost-test-chained-curl service exited with a 0/SUCCESS status"
ansible.builtin.assert:
that:
- 'service_chained_curl.status.ExecMainStatus == "0"'
success_msg: "Service has exited with a 0/SUCCESS status"
fail_msg: "Unexpected service status code: '{{ service_chained_curl.status.ExecMainStatus }}'"