prometheus.yml #3

  • //
  • guest/
  • russell_jackson/
  • ansible-sdp/
  • roles/
  • perforce-sdp-monitoring/
  • tasks/
  • prometheus.yml
  • View
  • Commits
  • Open Download .zip Download (2 KB)
---
# Install and configure p4prometheus and its rsyslog prerequisite.
- name: "Install rsyslog"
  ansible.builtin.package:
    name: "rsyslog"
    state: present

- name: "Query Perforce server case handling"
  become: true
  become_user: "{{ perforce_user }}"
  ansible.builtin.shell:
    cmd: "source /p4/common/bin/p4_vars {{ perforce_id }} && p4 -ztag -F %caseHandling% info"
    executable: /bin/bash
  register: p4_case_handling
  changed_when: false

- name: "Download and set permissions on p4prometheus install script"
  ansible.builtin.get_url:
    url: https://raw.githubusercontent.com/perforce/p4prometheus/master/scripts/install_p4prom.sh
    dest: /p4/install_p4prom.sh
    mode: '0755'
    owner: "{{ perforce_user }}"
    group: "{{ perforce_group }}"
  retries: 3
  delay: 10
  register: p4prom_download
  until: p4prom_download is not failed

- name: "Download p4prometheus install common library"
  ansible.builtin.get_url:
    url: https://raw.githubusercontent.com/perforce/p4prometheus/master/scripts/p4prom_common.sh
    dest: /p4/p4prom_common.sh
    mode: '0755'
    owner: "{{ perforce_user }}"
    group: "{{ perforce_group }}"
  retries: 3
  delay: 10
  register: p4prom_common_download
  until: p4prom_common_download is not failed

- name: "Set case_sensitive_server to false in install script"
  ansible.builtin.replace:
    path: /p4/install_p4prom.sh
    regexp: 'case_sensitive_server: true'
    replace: 'case_sensitive_server: false'
  when: p4_case_handling.stdout == "insensitive"

- name: "Set output_cmds_by_ip to true in install script"
  ansible.builtin.replace:
    path: /p4/install_p4prom.sh
    regexp: 'output_cmds_by_ip: false'
    replace: 'output_cmds_by_ip: true'

- name: "Run the p4prometheus install script"
  ansible.builtin.command: "/p4/install_p4prom.sh {{ perforce_id }} -m {{ p4prometheus_metrics_dir }}"
  args:
    # The installer drops the p4prometheus binary here; skip the re-run once it
    # exists so the task is idempotent. (Re-run the install by removing the
    # binary or with install_p4prom.sh directly when upgrading p4prometheus.)
    creates: "/usr/local/bin/p4prometheus"

- name: "Create p4prometheus location file"
  ansible.builtin.template:
    src: "./p4prometheus_location.j2"
    dest: "{{ p4prometheus_metrics_dir }}/location.prom"
    owner: "{{ perforce_user }}"
    group: "{{ perforce_group }}"
    mode: '0644'
# Change User Description Committed
#3 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.
#2 32850 Russell C. Jackson (Rusty) perforce-sdp-monitoring: download p4prom_common.sh companion lib required by upstream install_p4prom.sh
#1 32842 Russell C. Jackson (Rusty) Reorganize ansible-sdp into per-concern task files; ansible-lint production-clean

- Split install.yml/cron.yml/dependencies.yml and the monitoring role into thin
  orchestrators plus single-purpose phase files; extract shared steps into
  tasks/common/ (fetch_sdp, fetch_binaries, run_mkdirs, copy_ssl,
  configure_broker, sudoers).
- Full best-practices pass: FQCN, true/false, quoted modes, changed_when, loops,
  document-start markers; fill both roles' meta; add .ansible-lint.
- RedHat parity: parameterized EPEL enable, dnf, full upgrade, sysctl/bbr tuning.
- Collapse the 12 journal-rotation cron tasks to one; consolidate duplicate
  download/broker logic; fix broken tests/test.yml role reference.
- Validated ansible-lint clean at the production profile (ansible-core 2.21 /
  python 3.12) and ansible-playbook --syntax-check OK.