homelab/roles/haproxy/tasks/main.yml

71 lines
1.7 KiB
YAML
Raw Normal View History

2024-09-29 18:04:34 +05:00
---
2024-10-14 23:58:06 +05:00
- name: Create haproxy docker network
2024-09-29 18:04:34 +05:00
become: true
2024-10-14 23:58:06 +05:00
community.docker.docker_network:
2024-09-29 18:04:34 +05:00
name: haproxy
2024-10-14 23:58:06 +05:00
- name: Create haproxy dirs
become: true
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "1755"
owner: root
group: root
loop:
- /etc/haproxy
- /etc/haproxy/errors
- name: Copy haproxy config to a temporary location
become: true
ansible.builtin.copy:
src: haproxy.cfg
dest: /tmp/haproxy.cfg
- name: Validate haproxy config
become: true
community.docker.docker_container:
name: haproxy-config-test
image: "{{ haproxy_image }}"
command: haproxy -c -f /tmp/haproxy.cfg
networks:
- name: haproxy
volumes:
- /tmp/haproxy.cfg:/tmp/haproxy.cfg
- /etc/haproxy/certs:/usr/local/etc/haproxy/certs:ro
detach: no
- name: Remove temporary container
become: true
community.docker.docker_container:
name: haproxy-config-test
state: absent
2024-09-29 18:04:34 +05:00
- name: Copy haproxy config
become: true
ansible.builtin.copy:
src: haproxy.cfg
dest: /etc/haproxy/haproxy.cfg
register: haproxy
2024-10-14 23:58:06 +05:00
- name: Copy errors
become: true
ansible.builtin.copy:
src: errors/{{ item }}.http
dest: /etc/haproxy/errors/{{ item }}.http
loop: [400, 403, 408, 500, 502, 503, 504]
- name: Create haproxy container
become: true
community.docker.docker_container:
name: haproxy
image: "{{ haproxy_image }}"
networks:
- name: haproxy
volumes:
- /etc/haproxy:/usr/local/etc/haproxy:ro
sysctls:
net.ipv4.ip_unprivileged_port_start: 0
ports:
- 80:80
- 389:389
2024-10-14 23:58:06 +05:00
- 443:443
restart_policy: unless-stopped
2024-09-29 18:04:34 +05:00
- name: Reload haproxy
become: true
when: haproxy.changed
2024-10-14 23:58:06 +05:00
ansible.builtin.shell: docker kill -s HUP haproxy