diff --git a/doc/source/container-roles.rst b/doc/source/container-roles.rst index 3a329a55f..d2d7a7f3f 100644 --- a/doc/source/container-roles.rst +++ b/doc/source/container-roles.rst @@ -3,6 +3,7 @@ Container Roles .. zuul:autorole:: build-container-image .. zuul:autorole:: build-docker-image +.. zuul:autorole:: collect-container-logs .. zuul:autorole:: deploy-openshift .. zuul:autorole:: install-docker .. zuul:autorole:: install-kubernetes diff --git a/roles/collect-container-logs/README.rst b/roles/collect-container-logs/README.rst new file mode 100644 index 000000000..52e452c4c --- /dev/null +++ b/roles/collect-container-logs/README.rst @@ -0,0 +1,8 @@ +An ansible role to collect all container logs. + +**Role Variables** + +.. zuul:rolevar:: container_command + :default: docker + + Container run-time CLI command diff --git a/roles/collect-container-logs/defaults/main.yaml b/roles/collect-container-logs/defaults/main.yaml new file mode 100644 index 000000000..1d18111b7 --- /dev/null +++ b/roles/collect-container-logs/defaults/main.yaml @@ -0,0 +1 @@ +container_command: docker \ No newline at end of file diff --git a/roles/collect-container-logs/tasks/main.yaml b/roles/collect-container-logs/tasks/main.yaml new file mode 100644 index 000000000..ef7bc9607 --- /dev/null +++ b/roles/collect-container-logs/tasks/main.yaml @@ -0,0 +1,22 @@ +- 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([]) }}" + shell: "{{ container_command }} logs {{ item }} &> {{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}/{{ item }}.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 diff --git a/test-playbooks/registry/test-registry-post.yaml b/test-playbooks/registry/test-registry-post.yaml index 2fda35820..5242b7bf9 100644 --- a/test-playbooks/registry/test-registry-post.yaml +++ b/test-playbooks/registry/test-registry-post.yaml @@ -1,24 +1,3 @@ - hosts: all - tasks: - - 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([]) }}" - shell: "{{ container_command }} logs {{ item }} &> {{ ansible_user_dir }}/zuul-output/logs/{{ container_command }}/{{ item }}.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 + roles: + - collect-container-logs