--- # Copyright Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # Create data collection directories - name: Ensure directories exist ansible.builtin.file: path: "{{ cifmw_validations_basedir }}/{{ item }}" state: directory mode: "0755" loop: - artifacts - logs - name: Initialize variables needed for generating polarion xml file ansible.builtin.set_fact: _cifmw_validations_results: {} # We can execute all defined validations when cifmw_validation_run_all is defined. # Else, we will skip this and run only the explicitly defined validations from # cifmw_validations_list - name: Run all validations if required when: cifmw_validations_run_all | bool block: - name: Find all validations register: found_validations ansible.builtin.find: paths: "{{ cifmw_validations_default_path }}" patterns: '*.yml' recurse: true # We need to exclude this file from the list of found validations to avoid an infinite loop. excludes: "{{ cifmw_validations_default_path }}/main.yml" - name: Run all found validations ansible.builtin.include_tasks: file: run_validation.yml loop: "{{ found_validations.files }}" - name: Run selected validations when: not cifmw_validations_run_all | bool block: - name: Assert all listed validations exist ansible.builtin.stat: path: "{{ cifmw_validations_default_path }}/{{ item }}" loop: "{{ cifmw_validations_list }}" register: validation_exists failed_when: not validation_exists.stat.exists - name: Run validations ansible.builtin.include_tasks: file: run_validation.yml loop: "{{ cifmw_validations_list }}" - name: Create validations directory ansible.builtin.file: path: "{{ cifmw_validations_xml_status_file_dir }}" state: directory mode: "0755" - name: Create the XML file ansible.builtin.copy: content: "{{ _cifmw_validations_results | cifmw_validations_xml_filter }}" dest: "{{ cifmw_validations_xml_status_file_dir }}/validations_results.xml" mode: "0644" - name: Fail job when validations fail ansible.builtin.assert: that: - _cifmw_validations_results.values() | selectattr('error', 'defined') | length == 0 msg: "One or more validations failed"