stage-output: Add the ability to add .txt extensions to files

So that this can more easily work with files like '/var/log/syslog',
make it so that if the user specifies "logs_txt" then the file gets
a .txt extension before being placed in the logs directory.

The existing extensions_to_txt variable doesn't work for this because
it requires an existing extension.

Change-Id: I34fea0c44030c04a5540d6b62976557143289196
This commit is contained in:
James E. Blair 2019-01-31 10:48:58 -08:00
parent 2abb8a1302
commit 98628f718a
2 changed files with 14 additions and 3 deletions

View File

@ -23,6 +23,16 @@ intended to be used before output fetching in a base job's post-playbook.
null overrides the will of a parent job to copy something instructing
not to copy.
If the type is suffixed with ``_txt``, then the item will have
``.txt`` appended to its name. For example::
.. code-block:: yaml
zuul_copy_output:
/var/log/syslog: logs_txt
Will copy ``/var/log/syslog`` to ``logs/syslog.txt``.
.. zuul:rolevar:: stage_dir
:default: {{ ansible_user_dir }}

View File

@ -27,12 +27,13 @@
# 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`.
# included of folders specified in `zuul_copy_output` (except for logs_txt,
# which is handled here).
- 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 }}"
dest: "{{ item.item.value.split('_')[0] }}/{{ item.stat.path|basename|regex_replace('^(\\..*)$', '_\\1') }}{% if item.item.value.endswith('_txt') %}.txt{% endif %}"
type: "{{ item.item.value.split('_')[0] }}"
with_items: "{{ sources.results }}"
when:
- item.stat.exists