verify.yml #1

  • //
  • guest/
  • russell_jackson/
  • ansible-sdp/
  • roles/
  • perforce-sdp-monitoring/
  • molecule/
  • default/
  • verify.yml
  • View
  • Commits
  • Open Download .zip Download (2 KB)
---
# Verify: the monitoring probes are deployed, scheduled, and actually emit
# Prometheus metrics against the live p4d.
- name: Verify
  hosts: all
  become: true
  tasks:
    - name: "Probe scripts are installed and executable"
      ansible.builtin.stat:
        path: "/p4/common/bin/{{ item }}"
      loop:
        - p4_healthcheck.sh
        - p4_disk_space.sh
        - p4_network_latency.sh
      register: probe_scripts

    - name: "Assert all probe scripts exist and are executable"
      ansible.builtin.assert:
        that:
          - item.stat.exists
          - item.stat.executable
        fail_msg: "probe script missing or not executable: {{ item.item }}"
      loop: "{{ probe_scripts.results }}"
      loop_control:
        label: "{{ item.item }}"

    - name: "Read the perforce crontab"
      become: true
      become_user: "{{ perforce_user }}"
      ansible.builtin.command: "crontab -l"
      register: crontab_out
      changed_when: false

    - name: "Assert the monitoring cron jobs are scheduled"
      ansible.builtin.assert:
        that:
          - "'p4 health check' in crontab_out.stdout"
          - "'p4 disk space check' in crontab_out.stdout"
          - "'p4 network latency check' in crontab_out.stdout"
        fail_msg: "monitoring cron jobs missing. crontab:\n{{ crontab_out.stdout }}"

    - name: "Confirm p4prometheus location file was rendered"
      ansible.builtin.stat:
        path: "{{ p4prometheus_metrics_dir }}/location.prom"
      register: location_prom

    - name: "Assert location.prom exists"
      ansible.builtin.assert:
        that: location_prom.stat.exists
        fail_msg: "{{ p4prometheus_metrics_dir }}/location.prom not found"

    - name: "Run the health-check probe by hand"
      become: true
      become_user: "{{ perforce_user }}"
      ansible.builtin.command: "/p4/common/bin/p4_healthcheck.sh"
      changed_when: false

    - name: "Read the health-check metric file"
      ansible.builtin.slurp:
        src: "{{ p4prometheus_metrics_dir }}/p4_healthcheck.prom"
      register: healthcheck_prom

    - name: "Assert the probe emitted p4_up=1 against the live server"
      ansible.builtin.assert:
        that: "'p4_up{instance=\"1\"} 1' in (healthcheck_prom.content | b64decode)"
        fail_msg: "health-check did not report the server up. Metric file:\n{{ healthcheck_prom.content | b64decode }}"
# Change User Description Committed
#1 32873 Russell C. Jackson (Rusty) Add full-integration Molecule scenarios for both ansible roles

roles/{perforce-sdp-install,perforce-sdp-monitoring}/molecule/default/ each with
molecule.yml + prepare.yml + converge.yml + verify.yml. Uses the docker driver
with geerlingguy systemd images on Ubuntu 22.04 and Rocky 9 (Debian + RedHat/EL).

- install: prepare creates SDP volume dirs; converge runs the role (fresh SDP
  install -> p4d up) then configure_new_server.sh; verify asserts the service is
  active, p4 info reports ServerID master, and runs the SDP functional test
  harness (run_sdp_tests).
- monitoring: prepare brings up + configures p4d via the install role; converge
  applies the monitoring role; verify checks the probe scripts/cron are deployed
  and runs p4_healthcheck.sh, asserting p4_up=1 against the live server.

Idempotence step omitted (a full p4d install is not idempotent). README documents
prerequisites and usage. Validated with ansible-playbook --syntax-check and
ansible-lint (production profile clean for both the scenarios and the whole
project).