diff options
Diffstat (limited to 'playbooks/metal3-ci/fetch_pod_logs.yaml')
-rw-r--r-- | playbooks/metal3-ci/fetch_pod_logs.yaml | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/playbooks/metal3-ci/fetch_pod_logs.yaml b/playbooks/metal3-ci/fetch_pod_logs.yaml new file mode 100644 index 000000000..077b2d319 --- /dev/null +++ b/playbooks/metal3-ci/fetch_pod_logs.yaml @@ -0,0 +1,24 @@ +--- +- name: Create the target directory + file: + path: "{{ logs_management_cluster }}/{{ namespace }}/{{ pod }}" + state: directory + +- name: Fetch pod information + command: kubectl get pod -n "{{ namespace }}" -o json "{{ pod }}" + register: pod_result + +- name: Process pod JSON + set_fact: + pod_json: "{{ pod_result.stdout | from_json }}" + +- name: Set container names + set_fact: + containers: "{{ pod_json.spec.containers | map(attribute='name') | list }}" + init_containers: "{{ pod_json.spec.initContainers | default([]) | map(attribute='name') | list }}" + +- name: Fetch container logs + shell: | + kubectl logs -n "{{ namespace }}" "{{ pod }}" "{{ item }}" \ + > "{{ logs_management_cluster }}/{{ namespace }}/{{ pod }}/{{ item }}.log" 2>&1 + loop: "{{ containers + init_containers }}" |