Clark Boylan e323dc117b Don't use item in collect container logs loop
The default loop variable 'item' cannot be nested. Because roles like
collect-container-logs may be called from higher level loops that use
'item' we override the loop control var to a name that should be unique.

This should probably be done to all of the other roles in zuul-jobs too.

Change-Id: I2f647596dd40c662aa7447e3d3c8844a77c6b109
2020-02-01 14:24:16 -08:00

27 lines
945 B
YAML

- name: List containers
command: "{{ container_command }} ps -a --format '{{ '{{ .Names }}' }}'"
register: docker_containers
ignore_errors: true
- name: Create container log dir
file:
path: "{{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}"
state: directory
- 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: loop_container_name
shell: "{{ container_command }} logs {{ loop_container_name }} &> {{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}/{{ loop_container_name }}.txt"
args:
executable: /bin/bash
ignore_errors: true
- name: Open container logs permissions
file:
dest: "{{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}"
mode: u=rwX,g=rX,o=rX
recurse: yes