forked from GovStackWorkingGroup/IM_Demo_InstallingScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haproxy-certs.yaml
43 lines (34 loc) · 1.35 KB
/
haproxy-certs.yaml
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
- name: Setup haproxy certificates
hosts: all
remote_user: root
vars_files: vars_with_secret.yml
vars:
words: "{{ inventory_hostname.split('.') }}"
domain_name: "{{ words[0]+'.ext.'+'.'.join(words[1:]) }}"
tasks:
- name: Store haproxy certs
set_fact:
haproxy_certs: "{{ [ '/etc/letsencrypt/certs/haproxy.crt' ] }}"
- name: Make certificate compatible with haproxy
ansible.builtin.shell: "cat /etc/letsencrypt/certs/fullchain_{{ domain_name }} /etc/letsencrypt/keys/{{ domain_name }}.key > /etc/letsencrypt/certs/haproxy.crt"
args:
chdir: /etc/letsencrypt/certs/
become: true
- name: Store haproxy certs for subdomains
set_fact:
haproxy_certs: "{{ haproxy_certs + [ '/etc/letsencrypt/certs/haproxy_'+item+'.crt' ] }}"
loop: "{{ subdomains }}"
- name: Make subdomain certificate compatible with haproxy
ansible.builtin.shell: "cat /etc/letsencrypt/certs/fullchain_{{ item+'.'+domain_name }} /etc/letsencrypt/keys/{{ item+'.'+domain_name }}.key > /etc/letsencrypt/certs/haproxy_{{ item }}.crt"
args:
chdir: /etc/letsencrypt/certs/
become: true
loop: "{{ subdomains }}"
- name: -v to print haproxy_certs as inserted in haproxy config
debug:
msg: "{{' crt '.join(haproxy_certs)}}"
verbosity: 1
- name: Restart haproxy
service:
name: haproxy
state: restarted