system-config/playbooks/zuul/run-production-playbook.yaml
Ian Wienand a51784a513
run-production-playbook: redirect via ansible logger
Currently this logs to /var/log/ansible.log via the log_path setting
in the Ansible config, and we also redirect output to a file.  The
stdout dump is the primary debugging method, and contains the same
info as what is put into /var/log/ansible.log by Ansible logging.

Instead, set ANSIBLE_LOG_PATH to /dev/null these logs, and just save
the stdout output.  While we're here, save stderr too.

This way if you manually run Ansible on bridge you've got logging by
default, but this should stop multiple runs of production Ansible via
Zuul all mushing together thier output into a fairly useless global
log file.

Change-Id: Iae32f501dc718f9bbfd403c6857ca7c8dc8767de
2025-03-12 09:16:47 +11:00

38 lines
1.8 KiB
YAML

- hosts: localhost
roles:
- add-bastion-host
- hosts: prod_bastion[0]
tasks:
- name: Run the production playbook and capture logs
block:
- name: Get a current timestamp
set_fact:
_log_timestamp: "{{ lookup('pipe', 'date +%Y-%m-%dT%H:%M:%S') }}"
# NOTE(ianw) : this gets parsed by the post playbook. If this
# is updated, that parsing should be too
- name: Log a playbook start header
become: yes
shell: 'echo "Running {{ _log_timestamp }}: ansible-playbook -v -f {{ infra_prod_ansible_forks }} /home/zuul/src/opendev.org/opendev/system-config/playbooks/{{ playbook_name }}" > /var/log/ansible/{{ playbook_name }}.log'
- name: Run specified playbook on bastion host and redirect output
become: yes
shell: 'ansible-playbook -v -f {{ infra_prod_ansible_forks }} /home/zuul/src/opendev.org/opendev/system-config/playbooks/{{ playbook_name }} >> /var/log/ansible/{{ playbook_name }}.log 2>&1'
register: _run
environment:
# Override the global config for zuul induced runs to not
# have a mixed-up ever-growing /var/log/ansible.log.
ANSIBLE_LOG_PATH: '/dev/null'
always:
- name: Send run stats
shell: |
# delta is in string format h:m:s.sss; convert to ms for statsd
{% set delta = _run.delta.split(':') %}
{% set delta_ms = ((delta[0]|int * 60 * 60 * 1000) + (delta[1]|int * 60 * 1000) + (delta[2]|float * 1000)) | int %}
echo 'bridge.ansible.{{ zuul.job }}.runtime:{{ delta_ms }}|ms' | nc -w 1 -u graphite.opendev.org 8125
echo 'bridge.ansible.{{ zuul.job }}.rc:{{ _run.rc }}|g' | nc -w 1 -u graphite.opendev.org 8125
args:
executable: '/bin/bash'