Ian Wienand f97b9b8b8b haproxy: redirect logs to a separate file
haproxy only logs to /dev/log; this means all our access logs get
mixed into syslog.  This makes it impossible to pick out anything in
syslog that might be interesting (and vice-versa, means you have to
filter out things if analysing just the haproxy logs).

It seems like the standard way to deal with this is to have rsyslogd
listen on a separate socket, and then point haproxy to that.  So this
configures rsyslogd to create /var/run/dev/log and maps that into the
container as /dev/log (i.e. don't have to reconfigure the container at
all).

We then capture this sockets logs to /var/log/haproxy.log, and install
rotation for it.

Additionally we collect this log from our tests.

Change-Id: I32948793df7fd9b990c948730349b24361a8f307
2022-07-07 21:29:13 +10:00

82 lines
1.6 KiB
YAML

- name: Install socat for haproxy management
package:
name: socat
state: present
- name: Ensure registry volume directories exists
file:
state: directory
path: "/var/haproxy/{{ item }}"
owner: 1000
group: 1000
loop:
- etc
- run
- dev
- name: Ensure haproxy config template available
assert:
that:
- haproxy_config_template is defined
- name: Write rsyslog file
copy:
src: rsyslog.d/49-haproxy.conf
dest: /etc/rsyslog.d/
owner: root
group: root
mode: 0644
register: _rsyslog_added
- name: Restart rsyslog if config updates
service:
name: rsyslog
state: restarted
when: _rsyslog_added.changed
- name: Add haproxy log rotation
include_role:
name: logrotate
vars:
logrotate_file_name: '/var/log/haproxy.log'
- name: Write haproxy config file
template:
src: '{{ haproxy_config_template }}'
dest: /var/haproxy/etc/haproxy.cfg
owner: 1000
group: 1000
mode: 0644
notify: Reload haproxy
- name: Ensure docker compose configuration directory
file:
path: /etc/haproxy-docker
state: directory
owner: root
group: root
mode: 0755
- name: Install docker-compose configuration
template:
src: docker-compose.yaml.j2
dest: /etc/haproxy-docker/docker-compose.yaml
owner: root
group: root
mode: 0644
notify: Reload haproxy
- name: Run docker-compose pull
shell:
cmd: docker-compose pull
chdir: /etc/haproxy-docker/
- name: Run docker-compose up
shell:
cmd: docker-compose up -d
chdir: /etc/haproxy-docker/
- name: Run docker prune to cleanup unneeded images
shell:
cmd: docker image prune -f