collect-container-logs: add role
We use this in a few different places and it's really useful to collect all the logs of all containers. Change-Id: Idc46a47f444bf48cd040f4f9724f3a6ee8bc8f8e
This commit is contained in:
parent
96300f3543
commit
228033e78a
@ -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
|
||||
|
8
roles/collect-container-logs/README.rst
Normal file
8
roles/collect-container-logs/README.rst
Normal file
@ -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
|
1
roles/collect-container-logs/defaults/main.yaml
Normal file
1
roles/collect-container-logs/defaults/main.yaml
Normal file
@ -0,0 +1 @@
|
||||
container_command: docker
|
22
roles/collect-container-logs/tasks/main.yaml
Normal file
22
roles/collect-container-logs/tasks/main.yaml
Normal file
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user