Files
openstack-ansible-haproxy_s…/tasks/haproxy_pre_install.yml
Denys Mishchenko 5413c41121 Temp directory for pki certificates
If directory is defined instead of certificate files, haproxy will
attempt to treat all files within as a pem bundled certs. And will fail
its configuration test. To avoid this we can put generated by pki
certificates into a temporary directory and them put only valid bundle
file into haproxy_ssl_cert_path.

Such approach allows us to put additional certificates to the directory
outside of the haproxy_server role and keep the directory clean. This
also eliminates the need to list all additional custom certificates and
calculated by role ones.

Additionally added a cleanup/move of the certs if haproxy_ssl_temp_path
set to be different from haproxy_ssl_cert_path which allows a transition
from old setup.

Change-Id: I3662195cb2248d8841e1525d5e6d86f84ca876d3
2025-05-28 17:34:00 +02:00

94 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 conf.d dir
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0755"
owner: haproxy
group: haproxy
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