prepare.yml #2

  • //
  • guest/
  • russell_jackson/
  • ansible-sdp/
  • roles/
  • perforce-sdp-install/
  • molecule/
  • default/
  • prepare.yml
  • View
  • Commits
  • Open Download .zip Download (2 KB)
---
# Prepare the container before the role runs.
# The role does NOT create the SDP volume directories (real deployments mount
# them as EBS/NFS/etc.), so create them here, and make sure the base utilities
# the role + p4d need are present.
- name: Prepare
  hosts: all
  become: true
  tasks:
    - name: "Create the SDP volume directories (role assumes they already exist)"
      ansible.builtin.file:
        path: "/{{ item }}"
        state: directory
        mode: '0755'
      loop:
        - hxdepots
        - hxlogs
        - hxmetadata

    - name: "Refresh the apt cache (Debian images ship without one)"
      ansible.builtin.apt:
        update_cache: true
      when: ansible_facts['os_family'] == 'Debian'

    # The EL9 image's nsswitch queries SSSD first (passwd: sss files ...), but no
    # SSSD runs in the container, so pam_unix account lookups fail with
    # "cannot retrieve authentication info" -- breaking sudo, crontab, etc. Drop
    # sss so PAM/NSS use the local files that the role populates.
    - name: "Use local files for NSS (no SSSD in the container) - RedHat"
      ansible.builtin.replace:
        path: /etc/nsswitch.conf
        regexp: '^((?:passwd|group|shadow):[ \t]+)sss[ \t]+'
        replace: '\1'
      when: ansible_facts['os_family'] == 'RedHat'

    # The EL9 image's pam_unix account phase returns AUTHINFO_UNAVAIL in the
    # container, so sudo and crontab (both 'account include system-auth') are
    # denied. Make the account phase permissive -- it only validates the local
    # account, which is always present here.
    - name: "Make the PAM account phase permissive in the container - RedHat"
      ansible.builtin.lineinfile:
        path: "{{ item }}"
        line: "account     sufficient    pam_permit.so"
        insertbefore: '^account'
        firstmatch: true
      loop:
        - /etc/pam.d/system-auth
        - /etc/pam.d/password-auth
      when: ansible_facts['os_family'] == 'RedHat'

    - name: "Ensure cron is available (the role installs the perforce crontab)"
      ansible.builtin.package:
        name: "{{ 'cron' if ansible_facts['os_family'] == 'Debian' else 'cronie' }}"
        state: present
# Change User Description Committed
#2 32879 Russell C. Jackson (Rusty) Harness: tolerate optional/absent scripts + accept ccheck PASS (Grade A or B)
#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).