9b17d6c9df
After a docker failure on a recent job I noticed a single file called "Got" in the container logs directory; turns out this had tried to parse the error message "Got permission denied while trying to connect to the Docker daemon socket ..." as containers. We don't want this to fail the job hence the ignores here. However, we shouldn't try to collect any logs if listing the containers fails. Move creating the directory first as that is safe. Change-Id: I41db956964f695cfcc15e30cab8cd4f8c31d3706
29 lines
986 B
YAML
29 lines
986 B
YAML
- name: Create container log dir
|
|
file:
|
|
path: "{{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}"
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: List containers
|
|
command: "{{ container_command }} ps -a --format '{{ '{{ .Names }}' }}'"
|
|
register: docker_containers
|
|
failed_when: false
|
|
|
|
- name: Save container logs
|
|
loop: "{{ docker_containers.stdout_lines | default([]) }}"
|
|
# We can't use the default 'item' because roles may be used in
|
|
# higher level loops and 'item' could conflict in that case.
|
|
loop_control:
|
|
loop_var: zj_container_name
|
|
shell: "{{ container_command }} logs {{ zj_container_name }} &> {{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}/{{ zj_container_name }}.txt"
|
|
args:
|
|
executable: /bin/bash
|
|
failed_when: false
|
|
when: docker_containers.rc == 0
|
|
|
|
- name: Open container logs permissions
|
|
file:
|
|
dest: "{{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}"
|
|
mode: u=rwX,g=rX,o=rX
|
|
recurse: yes
|