tripleo-validations/roles/oslo_config_validator/tasks/invalidate_config.yml

77 lines
3.0 KiB
YAML

---
# Copyright 2021 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.
- name: Getting possible invalid settings
become: true
validations_read_ini:
path: "{{ service.0.path }}"
section: "{{ service.1.section }}"
key: "{{ service.1.option }}"
loop: "{{ config_invalidations | subelements('invalid_settings') }}"
loop_control:
loop_var: service
label: "{{ service.1.section }}/{{ service.1.option }} in {{ service.0.path }}"
register: invalid_setting_validation
check_mode: false
- name: Printing invalid settings
when:
- oslo_config_validator_debug | bool
debug:
var: invalid_setting_validation
- name: Checking if settings are infact valid
when:
- setting.value
set_fact:
invalid_settings: >-
{% set errors = [] %}{%
set svc = setting.service.1 %}{%
set operator = svc.operator | default("not") %}{%
if 'separator' in svc %}{%
set setting_values = setting.value.split(svc.separator) | list %}{%
else %}{%
set setting_values = [setting.value] %}{%
endif %}{%
set setting_path = setting.service.0.path + ':' + svc.section + '/' + svc.option %}{%
for val in setting_values %}{%
if operator == "not" and val in svc.value_list %}{%
set _ = errors.append(setting_path +
' has an invalid value: ' + val +
' Forbidden values: ' + svc.value_list | join(',') ) %}{%
elif operator == "eq" and val not in svc.value_list %}{%
set _ = errors.append(setting_path +
' has an invalid value: ' + val +
' Should be one of these values: ' + svc.value_list | join(',') ) %}{%
elif operator == "lt" and val|int < svc.value_list.0 %}{%
set _ = errors.append(setting_path +
': Current value ' + val + ' is lesser than expected ' + svc.value_list.0 | string) %}{%
elif operator == "gt" and val|int > svc.value_list.0 %}{%
set _ = errors.append(setting_path +
': Current value ' + val + ' is greater than expected ' + svc.value_list.0 | string) %}{%
endif %}{%
endfor %}{{ invalid_settings | default([]) + errors }}
loop: "{{ invalid_setting_validation.results }}"
loop_control:
loop_var: setting
label: "{{ setting.service.1.section }}/{{ setting.service.1.option }} in {{ setting.service.0.path }}"
- name: Printing invalid settings
when:
- oslo_config_validator_debug | bool
debug:
var: invalid_settings