-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_letsencrypt.yml
91 lines (80 loc) · 2.3 KB
/
manage_letsencrypt.yml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
- name: lets encrypt play
hosts: letsencrypt-server
vars_files: group_vars/vault.yml
vars:
ansible_user: root
package_name: python3-certbot
letsencrypt_home: /var/lib/letsencrypt
ttl: 300
tasks:
- name: install
package: "name={{ package_name }} state=present"
- name: create user
user:
name: letsencrypt
shell: /bin/bash
home: "{{ letsencrypt_home }}"
- name: create home
file:
name: "{{ letsencrypt_home }}"
state: directory
owner: letsencrypt
group: letsencrypt
mode: 0770
- name: add dovecot to letencrypt group
user:
name: dovecot
groups: letsencrypt
append: yes
- name: create log dir
file:
name: /var/log/letsencrypt
state: directory
recurse: true
owner: letsencrypt
group: letsencrypt
mode: 0750
- name: create home etc
file:
name: /var/lib/letsencrypt/etc-letsencrypt
state: directory
recurse: true
owner: letsencrypt
group: letsencrypt
mode: u=rwX,g=rX,o-rwx
- name: create etc letsencrypt link
file:
path: /etc/letsencrypt
src: /var/lib/letsencrypt/etc-letsencrypt
state: link
force: yes
- name:
apt:
name: jq
state: present
- name: create letsencrypt wildcard token script
copy:
dest: /usr/local/sbin/certbot-gandi.sh
content: |
#!/bin/bash
set -e
APIOUTPUT="$( curl -s -H 'X-Api-Key: {{ gandi_api_key }}' https://dns.api.gandi.net/api/v5/zones )"
APIURL="$( echo $APIOUTPUT | jq -r --arg CERTBOT_DOMAIN "$CERTBOT_DOMAIN" '.[] | select(.name==$CERTBOT_DOMAIN) | .zone_records_href' )"
TXTNAME=_acme-challenge
CURL_OUTPUT=$( curl -s -X PUT -H "Content-Type: application/json" -H "X-Api-Key: {{ gandi_api_key }}" -d "{\"rrset_ttl\": "{{ ttl }}", \"rrset_values\": [\"$CERTBOT_VALIDATION\"]}" "$APIURL/$TXTNAME/TXT" )
if [[ ! $CURL_OUTPUT =~ "DNS Record Created" ]]; then
exit 1
fi
mode: 0550
owner: letsencrypt
group: letsencrypt
- name: disable certbot timer
systemd:
name: certbot.timer
state: stopped
enabled: false
- name: overwrite certbot cron, so that is no longer triggered as root
copy:
dest: /etc/cron.d/certbot
content: ""