103 lines
3.3 KiB
YAML
103 lines
3.3 KiB
YAML
- name: Register sources
|
|
stat:
|
|
path: "{{ item.key }}"
|
|
with_dict: "{{ zuul_copy_output }}"
|
|
register: sources
|
|
no_log: true
|
|
|
|
- name: Build the extensions list from a dict (or empty)
|
|
set_fact:
|
|
extension_list: >
|
|
{% set extensions = ['__do_not_match__'] -%}
|
|
{% if extensions_to_txt -%}
|
|
{% for extension, extension_bool in extensions_to_txt.items() -%}
|
|
{% if extension_bool -%}
|
|
{% set _ = extensions.append(extension) -%}
|
|
{% endif -%}
|
|
{% endfor -%}
|
|
{% endif -%}
|
|
{{- extensions -}}
|
|
|
|
- name: Build the extensions regular expression
|
|
set_fact:
|
|
extensions_regex: "^(.*)\\.({{ extension_list | join('|') }})$"
|
|
|
|
# TODO(andreaf) We might want to enforce that item.value is a valid value
|
|
# in docs, artifacts, logs. Null case already handled.
|
|
# NOTE(andreaf) Files or folders that start with a '.' are renamed to starting
|
|
# with an '_' else they would not be visible in the logs folder once uploaded.
|
|
# Extension changes are handled later via find as we want to rename files
|
|
# included of folders specified in `zuul_copy_output`.
|
|
- name: Set source and destination for files and folders
|
|
set_fact:
|
|
source: "{{ item.stat.path }}"
|
|
dest: "{{ item.item.value }}/{{ item.stat.path|basename|regex_replace('^(\\..*)$', '_\\1') }}"
|
|
type: "{{ item.item.value }}"
|
|
with_items: "{{ sources.results }}"
|
|
when:
|
|
- item.stat.exists
|
|
- item.item.value
|
|
register: results
|
|
no_log: true
|
|
|
|
- name: Build a list of source, dest dictionaries
|
|
set_fact:
|
|
all_sources: "{{ results.results | selectattr('ansible_facts', 'defined') | map(attribute='ansible_facts') | list }}"
|
|
|
|
- name: Ensure target folders exist
|
|
become: true
|
|
file:
|
|
path: "{{ stage_dir }}/{{ item }}"
|
|
state: directory
|
|
owner: "{{ ansible_user }}"
|
|
with_items:
|
|
- docs
|
|
- artifacts
|
|
- logs
|
|
|
|
- name: Copy files and folders to staging folder
|
|
# remote_src copy does not work recursively, synchronise is restricted by
|
|
# zuul, using command
|
|
command: cp -pRL {{ item.source}} {{ stage_dir }}/{{ item.dest }}
|
|
become: true
|
|
with_items: "{{ all_sources }}"
|
|
|
|
- name: Make all log files readable
|
|
file:
|
|
dest: "{{ stage_dir }}/logs"
|
|
mode: u=rwX,g=rX,o=rX
|
|
recurse: yes
|
|
become: yes
|
|
|
|
- name: Discover log files that match extension_list
|
|
find:
|
|
paths: "{{ stage_dir }}/logs"
|
|
patterns: "{{ extensions_regex }}"
|
|
use_regex: true
|
|
recurse: true
|
|
file_type: 'file'
|
|
register: log_files_to_rename
|
|
|
|
- name: Rename log files that match extension_list
|
|
shell: "mv {{ item.path }} {{ item.path | regex_replace(extensions_regex, '\\1_\\2.txt') }}"
|
|
with_items: "{{ log_files_to_rename.files }}"
|
|
chdir: "{{ stage_dir }}/logs"
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
# NOTE(andreaf) The ansible module does not support recursive archive, so
|
|
# using gzip is the only option here. The good bit is that gzip itself is
|
|
# almost idempotent, as it will not compress again files with .gz extension.
|
|
# gzip will however return 1 if any compressed file is encountered, so we
|
|
# must ignore that (there's no specific error code).
|
|
- name: Archive everything from docs sources
|
|
shell: gzip --recursive --best {{ item.dest }} || true
|
|
args:
|
|
chdir: "{{ stage_dir }}"
|
|
with_items: "{{ all_sources }}"
|
|
when:
|
|
- stage_compress_logs
|
|
- item.type == 'logs'
|
|
tags:
|
|
- skip_ansible_lint
|