- name: Register sources stat: path: "{{ item.key }}" with_dict: "{{ zuul_copy_output }}" register: sources no_log: true - name: Build the replace regex when the input is a list set_fact: extensions_regex: "{{ extensions_to_txt | join('|') | default('__do_not_replace__') }}" when: extensions_to_txt | type_debug == 'list' - name: Output a warning when input is a list debug: msg: "WARNING: extensions_to_txt is a list, values defined by parents will be overwritten" when: extensions_to_txt | type_debug == 'list' - name: Build a list when replace regex is a dict set_fact: extensions_regex: "{{ extensions_regex | default('___') }}|{{ item.key }}" with_dict: extensions_to_txt when: - extensions_to_txt | type_debug == 'dict' - item.value == True # NOTE(andreaf) Even if this is only executed for type 'dict', with_dict is # still invoked somehow and it's causing an error when the input is a list ignore_errors: yes - debug: var: extensions_regex # TODO(andreaf) We might want to enforce that item.value is a valid value # in docs, artifacts, logs. Null case already handled. # We don't check if the item is a file before renaming, but it is not likely # to have directories with log, yaml or conf extension. - 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('\\.(' + extensions_regex + ')$', '_\\1.txt') }}" 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 for text files 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 text files 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 }} with_items: "{{ all_sources }}" # 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'