Files
openstack-ansible-haproxy_s…/tasks/haproxy_service_config.yml
Dmitriy Rabotyagov c0da2e5095 Fix linters issue and metadata
With update of ansible-lint to version >=6.0.0 a lot of new
linters were added, that enabled by default. In order to comply
with linter rules we're applying changes to the role.

With that we also update metdata to reflect current state.

Change-Id: I8c316dd62ac22ccd9578bb0199ab8f25c0104f9a
2023-08-07 06:55:22 +00:00

127 lines
5.0 KiB
YAML

---
# Copyright 2014, Rackspace US, Inc.
#
# 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.
# NOTE(damiandabrowski): Deprecated haproxy_service_configs format
# conversion will be removed in 2024.1.
- name: Define blank _haproxy_service_configs_simplified variable
set_fact:
_haproxy_service_configs_simplified: []
- name: Append services to _haproxy_service_configs_simplified list
set_fact:
_haproxy_service_configs_simplified: "{{ _haproxy_service_configs_simplified + [(item.service is defined) | ternary(item.service, item)] }}"
loop: "{{ haproxy_service_configs }}"
###########################################################################
# Service frontends and backends assembled from fragments into haproxy.conf
###########################################################################
- name: Create haproxy service config files
template:
src: service.j2
dest: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}"
owner: root
group: haproxy
mode: "0640"
# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced
# with haproxy_service_configs in 2024.1.
loop: "{{ _haproxy_service_configs_simplified }}"
loop_control:
loop_var: service
when:
- (service.haproxy_backend_nodes is defined and
service.haproxy_backend_nodes | length > 0) or
(service.haproxy_backup_nodes is defined and
service.haproxy_backup_nodes | length > 0) or
service.haproxy_frontend_only | default('False')
- (service.haproxy_service_enabled | default('True')) | bool
- (service.state is not defined or service.state != 'absent')
notify: Regenerate haproxy configuration
tags:
- haproxy-service-config
- name: Remove haproxy service config files for absent services
file:
path: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}"
state: absent
notify: Regenerate haproxy configuration
# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced
# with haproxy_service_configs in 2024.1.
loop: "{{ _haproxy_service_configs_simplified }}"
loop_control:
loop_var: service
when:
- ((service.haproxy_service_enabled | default('True')) | bool) is falsy or
(service.state is defined and service.state == 'absent')
tags:
- haproxy-service-config
###########################################################################
# Map files assembled from fragments from each service into <map-name>.map
###########################################################################
- name: Create haproxy map fragment directories
file:
state: directory
path: "/etc/haproxy/map.conf.d/{{ item }}"
owner: root
group: haproxy
mode: "0750"
# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced
# with haproxy_service_configs in 2024.1.
loop: >-
{{
_haproxy_service_configs_simplified | selectattr('haproxy_map_entries', 'defined') | map(attribute='haproxy_map_entries') | flatten |
map(attribute='name') | unique
}}
# create map entries when the service is enabled and an existing map fragment is not absent
- name: Create haproxy map files
vars:
map_file: "/etc/haproxy/map.conf.d/{{ item.1.name }}/{{ item.1.order | default('00') }}-{{ item.0.haproxy_service_name }}.map"
template:
src: map.j2
dest: "{{ map_file }}"
owner: root
group: haproxy
mode: "0640"
# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced
# with haproxy_service_configs in 2024.1.
with_subelements:
- "{{ _haproxy_service_configs_simplified | selectattr('haproxy_map_entries', 'defined') }}"
- haproxy_map_entries
when:
- (item.0.haproxy_service_enabled | default(True)) | bool
- item.1.state | default('present') != 'absent'
notify: Regenerate maps
register: map_create
# remove map entries when the service is not enabled, the service is absent or the map is absent
- name: Delete unused map entries
file:
state: absent
path: "/etc/haproxy/map.conf.d/{{ item.1.name }}/{{ item.1.order | default('00') }}-{{ item.0.haproxy_service_name }}.map"
when:
- (item.0.haproxy_service_enabled | default('True')) | bool is falsy or
(item.0.state is defined and item.0.state == 'absent') or
(item.1.state | default('present') == 'absent')
# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced
# with haproxy_service_configs in 2024.1.
with_subelements:
- "{{ _haproxy_service_configs_simplified | selectattr('haproxy_map_entries', 'defined') }}"
- haproxy_map_entries
notify: Regenerate maps
register: map_delete