From 146fa7b2e616ec4f2ba15e8445a666a086549cc3 Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Wed, 31 Jan 2018 20:54:05 +0000 Subject: [PATCH] Change the list of extensions to a dict The stage-output role accepts a list of extensions to be replaced as txt so that they can be seen directly from within a web browser. Using a list means that children jobs cannot add to the parent setting, only overwrite. Adding support for dicts while preserving, at least for now, support for lists - to avoid breaking existing implementations. Change-Id: Ifc4b2070c5844e51acb9ad5d512e9f25f5bdd7ef --- roles/stage-output/README.rst | 7 ++++--- roles/stage-output/tasks/main.yaml | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/roles/stage-output/README.rst b/roles/stage-output/README.rst index 9e5e848dd..3dd8d37bc 100644 --- a/roles/stage-output/README.rst +++ b/roles/stage-output/README.rst @@ -31,7 +31,7 @@ intended to be used before output fetching in a base job's post-playbook. .. zuul:rolevar:: extensions_to_txt :default: null - A list of file extensions to be replaced with .txt when staging. + A dict of file extensions to be replaced with .txt when staging. This can be useful to ensure that text files with an extension not registered in the web server may be viewed via browser when uploaded to a file server. @@ -43,8 +43,9 @@ intended to be used before output fetching in a base job's post-playbook. Example: extensions_to_txt: - - conf - - log + conf: True + log: True + txt: False zuul.conf --(staged as)--> zuul_conf.txt diff --git a/roles/stage-output/tasks/main.yaml b/roles/stage-output/tasks/main.yaml index fefc674ff..23eb19c14 100644 --- a/roles/stage-output/tasks/main.yaml +++ b/roles/stage-output/tasks/main.yaml @@ -4,9 +4,26 @@ with_dict: "{{ zuul_copy_output }}" register: sources -- name: Build the replace regex +- 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