From b099b439b49731fef6f81d3c23d138ec8aec4455 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 1 Apr 2020 20:03:07 -0500 Subject: [PATCH] Grab logs in the case of errors More importantly, put the log collection in an always section of block, otherwise we won't get logs if a playbook fails, which is pretty much exactly when we want to get logs. Change-Id: Ia8e581e522f75a5f5945bc2143eec63b93381a94 --- playbooks/zuul/run-production-playbook.yaml | 60 ++++++++++++--------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/playbooks/zuul/run-production-playbook.yaml b/playbooks/zuul/run-production-playbook.yaml index d91d131a07..f680bbdbdf 100644 --- a/playbooks/zuul/run-production-playbook.yaml +++ b/playbooks/zuul/run-production-playbook.yaml @@ -15,31 +15,41 @@ - hosts: bridge.openstack.org tasks: - - name: Log a playbook start header - become: yes - shell: 'echo "Running {{ ansible_date_time.iso8601 }}: ansible-playbook -v -f {{ ansible_forks }} /opt/system-config/playbooks/{{ playbook_name }}" > /var/log/ansible/{{ playbook_name }}.log' + - name: Ensure run dir + file: + state: directory + path: /var/run/ansible - - name: Run specified playbook on bridge.o.o and redirect output - become: yes - shell: 'ansible-playbook -v -f {{ ansible_forks }} /opt/system-config/playbooks/{{ playbook_name }} >> /var/log/ansible/{{ playbook_name }}.log' + - name: Run the production playbook and capture logs + block: - # Not using normal zuul job roles as bridge.openstack.org is not a - # test node with all the normal bits in place. - - name: Collect log output - synchronize: - dest: "{{ zuul.executor.log_root }}/{{ playbook_name }}.log" - mode: pull - src: "/var/log/ansible/{{ playbook_name }}.log" - verify_host: true - when: infra_prod_playbook_collect_log + - name: Log a playbook start header + become: yes + shell: 'echo "Running {{ ansible_date_time.iso8601 }}: ansible-playbook -v -f {{ ansible_forks }} /opt/system-config/playbooks/{{ playbook_name }}" > /var/log/ansible/{{ playbook_name }}.log' - - name: Return playbook log artifact to Zuul - when: infra_prod_playbook_collect_log - zuul_return: - data: - zuul: - artifacts: - - name: "Playbook Log" - url: "{{ playbook_name }}.log" - metadata: - type: text + - name: Run specified playbook on bridge.o.o and redirect output + become: yes + shell: 'ansible-playbook -v -f {{ ansible_forks }} /opt/system-config/playbooks/{{ playbook_name }} >> /var/log/ansible/{{ playbook_name }}.log' + + always: + + # Not using normal zuul job roles as bridge.openstack.org is not a + # test node with all the normal bits in place. + - name: Collect log output + synchronize: + dest: "{{ zuul.executor.log_root }}/{{ playbook_name }}.log" + mode: pull + src: "/var/log/ansible/{{ playbook_name }}.log" + verify_host: true + when: infra_prod_playbook_collect_log + + - name: Return playbook log artifact to Zuul + when: infra_prod_playbook_collect_log + zuul_return: + data: + zuul: + artifacts: + - name: "Playbook Log" + url: "{{ playbook_name }}.log" + metadata: + type: text