diff --git a/tasks/haproxy_service_config.yml b/tasks/haproxy_service_config.yml index 4dd67fd..0688e78 100644 --- a/tasks/haproxy_service_config.yml +++ b/tasks/haproxy_service_config.yml @@ -13,6 +13,12 @@ # 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: Append services to _haproxy_service_configs_simplified list + set_fact: + _haproxy_service_configs_simplified: "{{ _haproxy_service_configs_simplified | default([]) + [ (item.service is defined) | ternary(item.service, item) ] }}" + loop: "{{ haproxy_service_configs }}" ########################################################################### # Service frontends and backends assembled from fragments into haproxy.conf @@ -22,10 +28,9 @@ template: src: service.j2 dest: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}" -# NOTE(damiandabrowski): Deprecated haproxy_service_configs format -# conversion will be removed in 2024.1. -# loop: "{{ haproxy_service_configs }}" - loop: "{{ haproxy_service_configs[0].service is defined | ternary(haproxy_service_configs | map(attribute='service'), haproxy_service_configs) | list }}" +# 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: @@ -45,10 +50,9 @@ path: "/etc/haproxy/conf.d/{{ service.haproxy_service_name }}" state: absent notify: Regenerate haproxy configuration -# NOTE(damiandabrowski): Deprecated haproxy_service_configs format -# conversion will be removed in 2024.1. -# loop: "{{ haproxy_service_configs }}" - loop: "{{ haproxy_service_configs[0].service is defined | ternary(haproxy_service_configs | map(attribute='service'), haproxy_service_configs) | list }}" +# 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: @@ -65,7 +69,9 @@ file: state: directory path: "/etc/haproxy/map.conf.d/{{ item }}" - with_items: "{{ haproxy_service_configs | selectattr('haproxy_map_entries', 'defined') | map(attribute='haproxy_map_entries') | flatten | map(attribute='name') | unique }}" +# 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 @@ -74,8 +80,10 @@ template: src: map.j2 dest: "{{ map_file }}" +# NOTE(damiandabrowski): _haproxy_service_configs_simplified should be replaced +# with haproxy_service_configs in 2024.1. with_subelements: - - "{{ haproxy_service_configs | selectattr('haproxy_map_entries', 'defined') }}" + - "{{ _haproxy_service_configs_simplified | selectattr('haproxy_map_entries', 'defined') }}" - haproxy_map_entries when: - (item.0.haproxy_service_enabled | default(True)) | bool @@ -92,8 +100,10 @@ - (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 | selectattr('haproxy_map_entries', 'defined') }}" + - "{{ _haproxy_service_configs_simplified | selectattr('haproxy_map_entries', 'defined') }}" - haproxy_map_entries notify: regenerate maps register: map_delete