Files
kolla-ansible/ansible/roles/service-config-validate/tasks/validate.yml
Ivan Halomi 19af5826fc Move actions to kolla_container_facts
Move actions responsible for info about containers
from kolla_container module to kolla_container_facts.
Also fixes a bug with inconsistencies between docker
and podman in kolla_container_facts.

Closes-bug: #2084878
Change-Id: I1db88e28a828ebf073f018b2bae1d9556ec22807
Signed-off-by: Ivan Halomi <ivan.halomi@tietoevry.com>
Signed-off-by: Martin Hiner <martin.hiner@tietoevry.com>
Signed-off-by: Roman Krček <roman.krcek@tietoevry.com>
2025-02-07 09:40:43 +00:00

51 lines
1.9 KiB
YAML

---
- name: "{{ project_name }} : {{ service.container_name }} | Get info on container"
become: True
kolla_container_facts:
action: get_containers
container_engine: "{{ kolla_container_engine }}"
name:
- "{{ service.container_name }}"
register: container_info
- name: "{{ project_name }} : {{ service.container_name }} | Validate configurations"
become: True
command: >
{{ kolla_container_engine }} exec {{ service.container_name }}
bash -c "[[ -f {{ inner_item['config'] }} ]] && oslo-config-validator --config-file {{ inner_item['generator'] }} --input-file {{ inner_item['config'] }}"
when:
- container_info.containers | length > 0
register: result
failed_when: result.rc not in [0, 1] # rc 1 is expected when errors are found in the config file, or when the config file doesn't exist
with_items: "{{ service_config_validation }}"
loop_control:
label: "{{ inner_item['config'] | basename }}"
loop_var: inner_item
changed_when: False
- name: "{{ project_name }} : {{ service.container_name }} | Ensure log directory exists"
become: True
file:
path: "{{ output_dir }}"
state: directory
when:
- result.results | map(attribute='rc', default=0) | select('equalto', 1) | list | length > 0
- result.results | map(attribute='stderr', default="") | select('ne', "") | list | length > 0
delegate_to: localhost
- name: "{{ project_name }} : {{ service.container_name }} | Log configuration errors"
become: True
copy:
content: "{{ inner_item.stderr }}"
dest: "{{ output_dir }}/{{ inner_item.inner_item.config | basename }}.err"
when:
- container_info.containers | length > 0
- inner_item.rc is defined
- inner_item.rc == 1
- inner_item.stderr != ""
loop: "{{ result.results }}"
loop_control:
label: "{{ inner_item.inner_item.config | basename }}"
loop_var: inner_item
delegate_to: localhost