prepare.yml #2

  • //
  • guest/
  • russell_jackson/
  • ansible-sdp/
  • roles/
  • perforce-sdp-monitoring/
  • molecule/
  • default/
  • prepare.yml
  • View
  • Commits
  • Open Download .zip Download (1 KB)
---
# Prepare: stand up a real, configured commit-server for the monitoring role to
# target (it queries p4 info and installs p4prometheus against a live p4d).
- name: Prepare
  hosts: all
  become: true
  tasks:
    - name: "Create the SDP volume directories"
      ansible.builtin.file:
        path: "/{{ item }}"
        state: directory
        mode: '0755'
      loop:
        - hxdepots
        - hxlogs
        - hxmetadata

    - name: "Ensure cron is available"
      ansible.builtin.package:
        name: "{{ 'cron' if ansible_facts['os_family'] == 'Debian' else 'cronie' }}"
        state: present

    - name: "Install SDP and bring up p4d"
      ansible.builtin.include_role:
        name: perforce-sdp-install

    - name: "Configure the new commit-server (once)"
      become: true
      become_user: "{{ perforce_user }}"
      ansible.builtin.shell: >-
        /p4/sdp/Server/Unix/setup/configure_new_server.sh {{ perforce_id }}
        && touch /p4/.molecule_configured
      args:
        chdir: "/p4/sdp/Server/Unix/setup"
        creates: "/p4/.molecule_configured"
# Change User Description Committed
#2 32876 Russell C. Jackson (Rusty) Make both ansible roles idempotent (full converge re-runs cleanly)

Existence gate:
- main.yml: stat /p4/common/bin/p4_vars -> sdp_installed fact; gate the
  destructive cleanup (wipe sdp folder + crontab) on 'not sdp_installed' so a
  re-converge skips wipe/reinstall and only reconciles idempotent config.

Run-once installers gated with creates/checks:
- run_mkdirs.sh: creates /p4/common/bin/p4_vars (drop changed_when:true).
- pyenv: drop changed_when on the creates-guarded bootstrap; add creates for the
  Python build; gate p4python install on 'pip3 show p4python'.
- monitoring prometheus.yml: gate the p4prometheus install script on
  creates /usr/local/bin/p4prometheus.

changed_when:true lies fixed:
- login.yml: gate admin/service logins on 'p4 login -s' (only log in when no
  valid ticket); use command for the no-shell status check.
- network_interface.yml: ifup gated on the interface not already being UP.

touch/cron idempotence:
- authorized_keys touch: modification_time/access_time preserve.
- cron/common.yml: remove 'crontab -r' (cron/cronvar modules manage entries
  idempotently by name; cron.yml is now the authoritative crontab manager).
- install/crontab.yml removed + its include dropped: the SDP-generated p4.crontab
  load was redundant (cron.yml's reset discarded it every run).
- packages.yml: apt update_cache cache_valid_time=3600.

Molecule: configure_new_server gated behind a marker in the install converge and
monitoring prepare; re-added the 'idempotence' step to both scenarios'
test_sequence. ansible-lint production-clean; all playbooks syntax-check.
#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).