Files
openstack-ansible-haproxy_s…/tasks/haproxy_pre_install.yml
Jonathan Rosser dda11aa043 Reload haproxy when static files are changed
If the content of any static files are changed, haproxy must be
reloaded in order for them to be served rather than the previous
versions.

Change-Id: I72101fed2919014bbebbaf4323f72decbea8a638
Signed-off-by: Jonathan Rosser <jonathan.rosser@rd.bbc.co.uk>
2025-11-30 09:54:42 +00:00

96 lines
2.8 KiB
YAML

---
# Copyright 2015, 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(cloudnull):
# While the haproxy distro packages provide for an haproxy
# group this group is being created upfront to support
# log aggregation links as well as ensure common user
# functionality across various distros that we support.
- name: Create the haproxy system group
ansible.builtin.group:
name: "haproxy"
state: "present"
system: "yes"
tags:
- haproxy-group
# NOTE(cloudnull):
# While the haproxy distro packages provide for an haproxy
# user this user is being created upfront to support
# log aggregation links as well as ensure common user
# functionality across various distros that we support.
- name: Create the haproxy system user
ansible.builtin.user:
name: "haproxy"
group: "haproxy"
comment: "haproxy user"
shell: "/bin/false"
system: "yes"
createhome: "yes"
home: "/var/lib/haproxy"
tags:
- haproxy-user
- name: Create haproxy config directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0755"
owner: root
group: root
with_items:
- /etc/haproxy/conf.d
- "{{ haproxy_ssl_cert_path }}"
- "{{ haproxy_ssl_temp_path }}"
- name: Cleanup haproxy_ssl_cert_path if temp_path is used
when: "haproxy_ssl_cert_path != haproxy_ssl_temp_path"
block:
- name: Find crt and key files in the cert_path
ansible.builtin.find:
paths: "{{ haproxy_ssl_cert_path }}"
patterns: '*.crt,*.key'
register: old_certs
- name: Copy cert files to the temp_path
vars:
filename: "{{ item | basename }}"
ansible.builtin.copy:
remote_src: true
src: "{{ item }}"
dest: "{{ [haproxy_ssl_temp_path, filename] | path_join }}"
mode: "0644"
loop: "{{ old_certs['files'] | map(attribute='path') }}"
- name: Remove file from the old place
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop: "{{ old_certs['files'] | map(attribute='path') }}"
- name: Copy static files
ansible.builtin.copy:
content: "{{ item.content }}"
dest: "{{ item.dest }}"
mode: "0644"
owner: haproxy
group: haproxy
when:
- (item.condition | default(True))
loop: "{{ haproxy_static_files }}"
no_log: true
notify:
- Reload haproxy