summaryrefslogtreecommitdiff
path: root/roles/haproxy/tasks/main.yml
blob: f7464c8828c180ee772587fb4d3809ffc7bf1148 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
- name: "add certbot apt repo"
  apt_repository:
    repo: "deb http://deb.debian.org/debian stretch-backports main"

- name: "install certbot"
  apt:
    name: certbot
    default_release: stretch-backports

- name: "install daily cron job to create haproxy.pem"
  copy:
    content: |
      #!/bin/sh
      set -eu
      cd /etc/letsencrypt/live/haproxy
      cat fullchain.pem privkey.pem > /etc/ssl/haproxy.pem
      systemctl restart haproxy
    dest: /etc/cron.daily/haproxy.pem
    owner: root
    group: root
    mode: 0755

- name: "run certbot"
  shell: |
    set -eu
    certbot certonly \
            --standalone \
            --noninteractive \
            --email "{{ letsencrypt_email }}" \
            --agree-tos \
            --expand \
            --cert-name haproxy \
            --keep \
            --pre-hook "systemctl stop apache2 haproxy" \
            --post-hook "systemctl start apache2 haproxy" \
            -d "{{ haproxy_domain }}"
    /etc/cron.daily/haproxy.pem

- name: install haproxy
  apt:
    name: haproxy

- name: "install haproxy config"
  copy:
    src: haproxy.cfg
    dest: /etc/haproxy/haproxy.cfg

- name: enable and start haproxy
  service:
    state: restarted
    enabled: yes
    name: haproxy