zuul-jobs/roles/ara-report/tasks/main.yaml
Ian Wienand 6d23d20f2f linters: add names to blocks
This is preparation for a later version of ansbile-lint, which finds
missing names on blocks.  This seems a reasonable rule, and the
Ansible manual says [1]

  Names for blocks have been available since Ansible 2.3. We recommend
  using names in all tasks, within blocks or elsewhere, for better
  visibility into the tasks being executed when you run the playbook.

This simply adds a name tag for blocks that are missing it.  This
should have no operational change, but allows us to update the linter
in a follow-on change.

[1] https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html

Change-Id: I92ed4616775650aced352bc9088a07e919f1a25f
2022-07-27 17:13:39 +10:00

98 lines
3.1 KiB
YAML

- name: Install ARA
block:
- name: Check that ARA is installed
command: bash -c "type -p {{ ara_report_executable }}"
failed_when: false
register: ara_installed
- name: Warn if ARA is not installed
debug:
msg: |
ARA is not installed, no report will be available.
when: ara_installed.rc != 0
- name: Check that the ARA database exists
stat:
path: "{{ ara_database_path }}"
register: ara_db
- name: Warn if no database is found
debug:
msg: |
No report will be available because the ARA database was not found.
when: not ara_db.stat.exists
- name: Validate role configuration
assert:
that:
- ara_report_type in ['html', 'database']
- ara_compress_html in [true, false]
- ara_report_run in [true, false, 'failure']
rescue:
- name: Role validation rescue
debug:
msg: |
Something failed during the validation of the role configuration
and pre-requirements.
It is likely that no report will be available, please verify the
execution and the parameters of the role for details.
- name: Generate output
when:
- ara_installed.rc == 0
- ara_db.stat.exists
- ara_report_type == 'html'
block:
# Always generate (true), never (false) or only on failure ('failure')
# Additionally cover for edge cases where zuul_success might be undefined
- name: Generate ARA HTML output
command: "{{ ara_report_executable }} generate html {{ ara_report_path }}"
environment:
ARA_DATABASE: "sqlite:///{{ ara_database_path }}"
when: ara_report_run | bool or
(ara_report_run == 'failure' and not zuul_success | default(false) | bool)
register: ara_generated
- name: Compress ARA HTML output
command: gzip --recursive --best {{ ara_report_path }}
when:
- ara_compress_html | bool
- not ara_generated is skipped
- name: Return ARA report
when: not ara_generated is skipped
zuul_return:
data:
zuul:
artifacts:
- name: ARA report
url: "{{ ara_report_artifact_prefix }}{{ ara_report_path | regex_replace('\\/$', '') | basename }}"
rescue:
- name: HTML generation rescue
debug:
msg: |
Something failed during the generation of the HTML report.
Please verify the execution of the role for details.
- name: Save database
when:
- ara_installed.rc == 0
- ara_db.stat.exists
- ara_report_type == 'database'
- ara_report_run | bool or (ara_report_run == 'failure' and not zuul_success | default(false) | bool)
block:
- name: Create the ARA database report directory
file:
path: "{{ ara_report_path }}"
state: directory
mode: 0755
- name: Save the ARA database
command: cp {{ ara_database_path }} {{ ara_report_path }}
- name: Return ARA report
zuul_return:
data:
zuul:
artifacts:
- name: ARA report
url: "{{ ara_report_path | regex_replace('\\/$', '') | basename }}"