collect-logs: run in two stages

We should run and publish a minimal sets of files even without any host,
when we failed the run before inventory generation.

This change separates the collection step that runs on all hosts except
localhost, and the rest running on localhost. Running on localhost
always succeeds, even with an empty inventory.

Also add a log environment file for local collect-logs.sh runs that
does not upload logs.

Change-Id: I48d07d42be879026fb80afd73835484770006f85
This commit is contained in:
Attila Darazs 2016-12-02 16:12:24 +01:00
parent 1a3897c326
commit 2bb8b177bc
6 changed files with 106 additions and 97 deletions

View File

@ -0,0 +1,6 @@
---
# this file is intentionally left blank, it can be used to pass the "local"
# parameter to the collect-logs.sh CI script, resulting in using the default
# settings, collecting logs locally but not attempting to upload them anywhere
# we need at least one dummy value here
artcl_placeholder: true

View File

@ -1,7 +1,11 @@
--- ---
- name: Collect logs, create docs, publish - name: Collect logs
hosts: all:!localhost hosts: all:!localhost
gather_facts: no
roles: roles:
- role: collect-logs - collect-logs
- name: Create docs, publish logs
hosts: localhost
roles:
- {role: collect-logs, artcl_collect: false }

View File

@ -1,12 +1,13 @@
--- ---
- become: true
ignore_errors: true
block:
- name: Ensure required rpms for logging are installed
yum: name={{ item }} state=present
with_flattened:
- gzip
- tar
- name: Ensure required rpms for logging are installed
yum: name={{ item }} state=present
with_flattened:
- gzip
- tar
- block:
- name: Prepare directory with extra logs - name: Prepare directory with extra logs
file: dest=/var/log/extra state=directory file: dest=/var/log/extra state=directory
@ -138,20 +139,20 @@
file: file:
path: "/tmp/{{ inventory_hostname }}" path: "/tmp/{{ inventory_hostname }}"
state: absent state: absent
become: yes
become_user: root
ignore_errors: true
- name: Set default collect list - name: Set default collect list
set_fact: collect_list="{{ artcl_collect_list | join(' ') }}" set_fact:
collect_list: "{{ artcl_collect_list | join(' ') }}"
- name: Override collect list - name: Override collect list
set_fact: collect_list="{{ artcl_collect_override[inventory_hostname] | join(' ') }}" set_fact:
when: artcl_collect_override is defined and artcl_collect_override[inventory_hostname] is defined collect_list: "{{ artcl_collect_override[inventory_hostname] | join(' ') }}"
when:
- artcl_collect_override is defined
- artcl_collect_override[inventory_hostname] is defined
- name: Gather the logs to /tmp - name: Gather the logs to /tmp
become: yes become: yes
become_user: root
shell: > shell: >
mkdir -p /tmp/{{ inventory_hostname }}; mkdir -p /tmp/{{ inventory_hostname }};
for F in $(ls -d1 /var/log/rpm.list /var/log/extra {{ collect_list }}); do for F in $(ls -d1 /var/log/rpm.list /var/log/extra {{ collect_list }}); do
@ -197,21 +198,15 @@
state: absent state: absent
ignore_errors: true ignore_errors: true
- block: - delegate_to: localhost
when: artcl_gzip_only|bool
block:
- name: Extract the logs - name: Extract the logs
shell: > shell: >
chdir={{ artcl_collect_dir }} chdir={{ artcl_collect_dir }}
tar xf {{ inventory_hostname }}.tar; tar xf {{ inventory_hostname }}.tar;
when: artcl_gzip_only|bool
- name: delete the tar file after extraction - name: delete the tar file after extraction
file: file:
path: "{{ artcl_collect_dir }}/{{ inventory_hostname }}.tar" path: "{{ artcl_collect_dir }}/{{ inventory_hostname }}.tar"
state: absent state: absent
when: artcl_gzip_only|bool
- name: fetch and gzip the console log
shell: >
curl {{ lookup('env', 'BUILD_URL') }}/consoleText | gzip > {{ artcl_collect_dir }}/console.txt.gz
when: artcl_publish|bool and "{{ lookup('env', 'BUILD_URL') }}" != ""
delegate_to: localhost

View File

@ -1,43 +1,37 @@
--- ---
- block: - name: Ensure required python packages are installed
- name: Ensure required python packages are installed pip:
pip: requirements: "{{ local_working_dir }}/usr/local/share/ansible/roles/collect-logs/doc-requirements.txt"
requirements: "{{ local_working_dir }}/usr/local/share/ansible/roles/collect-logs/doc-requirements.txt"
- name: Unarchive shell scripts - name: Unarchive shell scripts
shell: > shell: >
gunzip "{{ artcl_collect_dir }}/undercloud/home/stack/{{ item }}.sh.gz"; gunzip "{{ artcl_collect_dir }}/undercloud/home/stack/{{ item }}.sh.gz";
with_items: "{{ artcl_create_docs_payload.included_deployment_scripts }}" with_items: "{{ artcl_create_docs_payload.included_deployment_scripts }}"
ignore_errors: yes ignore_errors: yes
when: artcl_gzip_only|bool when: artcl_gzip_only|bool
- name: Generate rST docs from scripts and move to Sphinx src dir
shell: >
awk -f "{{ local_working_dir }}/usr/local/share/ansible/roles/collect-logs/scripts/doc_extrapolation.awk" \
"{{ artcl_collect_dir }}/undercloud/home/stack/{{ item }}.sh" > \
"{{ artcl_docs_source_dir }}/{{ item }}.rst"
with_items: "{{ artcl_create_docs_payload.included_deployment_scripts }}"
ignore_errors: yes
- name: Generate rST docs from scripts and move to Sphinx src dir - name: Fetch static rST docs to include in output docs
shell: > shell: >
awk -f "{{ local_working_dir }}/usr/local/share/ansible/roles/collect-logs/scripts/doc_extrapolation.awk" \ cp "{{ artcl_docs_source_dir }}/../static/{{ item }}.rst" "{{ artcl_docs_source_dir }}"
"{{ artcl_collect_dir }}/undercloud/home/stack/{{ item }}.sh" > \ with_items: "{{ artcl_create_docs_payload.included_static_docs }}"
"{{ artcl_docs_source_dir }}/{{ item }}.rst" ignore_errors: yes
with_items: "{{ artcl_create_docs_payload.included_deployment_scripts }}"
ignore_errors: yes
- name: Fetch static rST docs to include in output docs - name: Generate fresh index.rst for Sphinx
shell: > template:
cp "{{ artcl_docs_source_dir }}/../static/{{ item }}.rst" "{{ artcl_docs_source_dir }}" src: index.rst.j2
with_items: "{{ artcl_create_docs_payload.included_static_docs }}" dest: "{{ artcl_docs_source_dir }}/index.rst"
ignore_errors: yes force: yes
- name: Generate fresh index.rst for Sphinx - name: Build docs with Sphinx
template: shell: >
src: index.rst.j2 sphinx-build -b html "{{ artcl_docs_source_dir }}" \
dest: "{{ artcl_docs_source_dir }}/index.rst" "{{ artcl_docs_build_dir }}" &> "{{ local_working_dir }}/sphinx_build.log"
force: yes
- name: Build docs with Sphinx
shell: >
sphinx-build -b html "{{ artcl_docs_source_dir }}" \
"{{ artcl_docs_build_dir }}" &> "{{ local_working_dir }}/sphinx_build.log"
delegate_to: localhost
run_once: true
when: artcl_gen_docs|bool

View File

@ -5,8 +5,12 @@
- name: Generate docs - name: Generate docs
include: create-docs.yml include: create-docs.yml
when: artcl_gen_docs|bool when:
- artcl_gen_docs|bool
- not artcl_collect|bool
- name: Publish logs - name: Publish logs
include: publish.yml include: publish.yml
when: artcl_publish|bool when:
- artcl_publish|bool
- not artcl_collect|bool

View File

@ -1,39 +1,45 @@
--- ---
- name: Ensure the collection directory exists
file:
path: "{{ artcl_collect_dir }}"
state: directory
- run_once: true - name: fetch and gzip the console log
delegate_to: localhost shell: >
block: curl {{ lookup('env', 'BUILD_URL') }}/consoleText | gzip > {{ artcl_collect_dir }}/console.txt.gz
- name: upload to the artifact server using pubkey auth when: lookup('env', 'BUILD_URL') != ""
command: rsync -av --quiet -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" {{ artcl_collect_dir }}/ {{ artcl_rsync_path }}/{{ lookup('env', 'BUILD_TAG') }}
retries: 5
delay: 60
when: artcl_use_rsync|bool and not artcl_rsync_use_daemon|bool
- name: upload to the artifact server using password auth - name: upload to the artifact server using pubkey auth
environment: command: rsync -av --quiet -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" {{ artcl_collect_dir }}/ {{ artcl_rsync_path }}/{{ lookup('env', 'BUILD_TAG') }}
RSYNC_PASSWORD: "{{ lookup('env', 'RSYNC_PASSWORD') }}" retries: 5
command: rsync -av --quiet {{ artcl_collect_dir }}/ {{ artcl_rsync_path }}/{{ lookup('env', 'BUILD_TAG') }} delay: 60
retries: 5 when: artcl_use_rsync|bool and not artcl_rsync_use_daemon|bool
delay: 60
when: artcl_use_rsync|bool and artcl_rsync_use_daemon|bool
- name: upload to swift based artifact server - name: upload to the artifact server using password auth
shell: swift upload --quiet --header "X-Delete-After:{{ artcl_swift_delete_after }}" {{ artcl_swift_container }}/{{ lookup('env', 'BUILD_TAG') }} * environment:
args: RSYNC_PASSWORD: "{{ lookup('env', 'RSYNC_PASSWORD') }}"
chdir: "{{ artcl_collect_dir }}" command: rsync -av --quiet {{ artcl_collect_dir }}/ {{ artcl_rsync_path }}/{{ lookup('env', 'BUILD_TAG') }}
changed_when: true retries: 5
environment: delay: 60
OS_AUTH_URL: "{{ artcl_swift_auth_url }}" when: artcl_use_rsync|bool and artcl_rsync_use_daemon|bool
OS_USERNAME: "{{ artcl_swift_username }}"
OS_PASSWORD: "{{ artcl_swift_password }}"
OS_TENANT_NAME: "{{ artcl_swift_tenant_name }}"
when: artcl_use_swift|bool
- name: use zuul_swift_upload.py to publish the files - name: upload to swift based artifact server
command: "{{ artcl_zuul_swift_upload_path }}/zuul_swift_upload.py --name {{ artcl_swift_container }} --delete-after {{ artcl_swift_delete_after }} {{ artcl_collect_dir }}" shell: swift upload --quiet --header "X-Delete-After:{{ artcl_swift_delete_after }}" {{ artcl_swift_container }}/{{ lookup('env', 'BUILD_TAG') }} *
when: artcl_use_zuul_swift_upload|bool args:
chdir: "{{ artcl_collect_dir }}"
changed_when: true
environment:
OS_AUTH_URL: "{{ artcl_swift_auth_url }}"
OS_USERNAME: "{{ artcl_swift_username }}"
OS_PASSWORD: "{{ artcl_swift_password }}"
OS_TENANT_NAME: "{{ artcl_swift_tenant_name }}"
when: artcl_use_swift|bool
- name: create the artifact location redirect file - name: use zuul_swift_upload.py to publish the files
template: command: "{{ artcl_zuul_swift_upload_path }}/zuul_swift_upload.py --name {{ artcl_swift_container }} --delete-after {{ artcl_swift_delete_after }} {{ artcl_collect_dir }}"
src: full_logs.html.j2 when: artcl_use_zuul_swift_upload|bool
dest: "{{ artcl_collect_dir }}/full_logs.html"
- name: create the artifact location redirect file
template:
src: full_logs.html.j2
dest: "{{ artcl_collect_dir }}/full_logs.html"