From 98628f718aa984a7b6b58711f34d8ea0b982d88f Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 31 Jan 2019 10:48:58 -0800 Subject: [PATCH] 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 --- roles/stage-output/README.rst | 10 ++++++++++ roles/stage-output/tasks/main.yaml | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/roles/stage-output/README.rst b/roles/stage-output/README.rst index 9da1b4d09..df746402e 100644 --- a/roles/stage-output/README.rst +++ b/roles/stage-output/README.rst @@ -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 }} diff --git a/roles/stage-output/tasks/main.yaml b/roles/stage-output/tasks/main.yaml index bee689baf..5d8890721 100644 --- a/roles/stage-output/tasks/main.yaml +++ b/roles/stage-output/tasks/main.yaml @@ -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