production-playbook logs : don't use ansible_date_time

ansible_date_time is actually the cached fact time that has little
bearing on the actual time this is running [1] -- which is what you
want to see when, for example, tracing backwards to see why some runs
are randomly timing out.

[1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html#ansible-facts

Change-Id: I8b5559178e29f8604edf6a42507322fc928afb21
changes/84/849784/1
Ian Wienand 7 months ago
parent 87306d239d
commit 3ab81bb834

@ -16,9 +16,13 @@
- 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') }}"
- name: Log a playbook start header
become: yes
shell: 'echo "Running {{ ansible_date_time.iso8601 }}: 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'
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 bridge.o.o and redirect output
become: yes
@ -113,7 +117,7 @@
copy:
remote_src: yes
src: "/var/log/ansible/{{ playbook_name }}.log"
dest: "/var/log/ansible/{{ playbook_name }}.log.{{ ansible_date_time.iso8601 }}"
dest: "/var/log/ansible/{{ playbook_name }}.log.{{ _log_timestamp }}"
- name: Cleanup old playbook logs on bridge
when: not infra_prod_playbook_collect_log

Loading…
Cancel
Save