Execution
Date 14 Dec 2025 10:15:01 +0000
Duration 00:06:33.21
Controller aio1.openstack.local
User root
Versions
Ansible 2.18.6
ara 1.7.4 / 1.7.4
Python 3.13.5
Summary
7 Hosts
567 Tasks
554 Results
37 Plays
221 Files
0 Records

File: /home/zuul/src/opendev.org/openstack/openstack-ansible-haproxy_server/tasks/haproxy_service_config.yml

---
# 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.

###########################################################################
# Service frontends and backends assembled from fragments into haproxy.conf
###########################################################################

- name: Create haproxy service config files
  ansible.builtin.template:
    src: service.j2
    dest: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}"
    owner: root
    group: haproxy
    mode: "0640"
  loop: "{{ haproxy_service_configs }}"
  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

- name: Remove haproxy service config files for absent services
  ansible.builtin.file:
    path: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}"
    state: absent
  notify: Regenerate haproxy configuration
  loop: "{{ haproxy_service_configs }}"
  loop_control:
    loop_var: service
  when:
    - ((service.haproxy_service_enabled | default('True')) | bool) is falsy or (service.state is defined and service.state == 'absent')

###########################################################################
# Map files assembled from fragments from each service into <map-name>.map
###########################################################################

- name: Create haproxy map fragment directories
  ansible.builtin.file:
    state: directory
    path: "/etc/haproxy/map.conf.d/{{ item }}"
    owner: root
    group: haproxy
    mode: "0750"
  loop: >-
    {{
      haproxy_service_configs | 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"
  ansible.builtin.template:
    src: map.j2
    dest: "{{ map_file }}"
    owner: root
    group: haproxy
    mode: "0640"
  with_subelements:
    - "{{ haproxy_service_configs | 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
  ansible.builtin.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')
  with_subelements:
    - "{{ haproxy_service_configs | selectattr('haproxy_map_entries', 'defined') }}"
    - haproxy_map_entries
  notify: Regenerate maps
  register: map_delete