Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions roles/haproxy/tasks/acme.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Create acme user
- name: "Create acme user"
ansible.builtin.user:
name: "acme"
state: "present"
Expand All @@ -8,19 +8,19 @@
- "haproxy"
append: true

- name: Install acl package so ansible can run as an unprivilegd user
- name: "Install acl package so ansible can run as an unprivilegd user"
ansible.builtin.package:
name: "acl"
state: "present"

- name: Clone the acme.sh repo
- name: "Clone the acme.sh repo"
ansible.builtin.git:
repo: "https://github.com/acmesh-official/acme.sh.git"
dest: "/opt/acmesh/"
version: "3.1.0"
update: true

- name: Install the acme.sh script
- name: "Install the acme.sh script"
ansible.builtin.shell:
cmd: |
sh /opt/acmesh/acme.sh --install --accountemail "{{ admin_email }}"
Expand All @@ -29,7 +29,7 @@
become: true
become_user: "acme"

- name: Set email address in acme config
- name: "Set email address in acme config"
ansible.builtin.lineinfile:
path: "/home/acme/.acme.sh/account.conf"
line: "ACCOUNT_EMAIL='{{ admin_email }}'"
Expand All @@ -38,11 +38,11 @@
group: "acme"
mode: "0600"

- name: Find CA account dir
- name: "Find CA account dir"
ansible.builtin.set_fact:
haproxy_acme_ca_dir: "/home/acme/.acme.sh/ca/{{ haproxy_acme_server | replace('https://', '') }}"

- name: Create the acme account
- name: "Create the acme account"
ansible.builtin.command:
cmd: |
/home/acme/.acme.sh/acme.sh
Expand All @@ -55,12 +55,12 @@
become: true
become_user: "acme"

- name: Remove default cronjob for renewal
- name: "Remove default cronjob for renewal"
ansible.builtin.file:
path: "/var/spool/cron/crontabs/acme"
state: "absent"

- name: Install cronjob for renewal
- name: "Install cronjob for renewal"
ansible.builtin.copy:
dest: "/etc/cron.d/acme-renew"
owner: "root"
Expand Down
20 changes: 10 additions & 10 deletions roles/haproxy/tasks/get_acme_certs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Create list of domains to request certificates for
- name: "Create list of domains to request certificates for"
ansible.builtin.set_fact:
haproxy_ssl_hosts: >
{{
Expand All @@ -12,10 +12,10 @@
| unique | sort
}}

- name: Check existence of acme CNAME records
- name: "Check existence of acme CNAME records"
ansible.builtin.command:
cmd: "dig +short -t CNAME '_acme-challenge.{{ item }}'"
register: haproxy_acme_cname
register: "haproxy_acme_cname"
failed_when: "haproxy_acme_cname.stdout == ''"
changed_when: false
loop: "{{ haproxy_ssl_hosts }}"
Expand All @@ -24,10 +24,10 @@
check_mode: false # this is safe run run, even in check mode
run_once: true

- name: Update certificates on one host at a time
- name: "Update certificates on one host at a time"
throttle: 1
block:
- name: Issue the certificates using acme
- name: "Issue the certificates using acme"
ansible.builtin.command:
cmd: |
/home/acme/.acme.sh/acme.sh
Expand All @@ -40,7 +40,7 @@
--dnssleep 3
--server "{{ haproxy_acme_server }}"
--domain "{{ item }}"
{{ acme_account.changed | ternary('--force', '') }}
{{ acme_account.changed OR (acme_force_renewal is defined AND acme_force_renewal) | ternary('--force', '') }}
environment:
ACMEDNS_BASE_URL: "{{ haproxy_acmedns.baseurl }}"
ACMEDNS_USERNAME: "{{ haproxy_acmedns.username }}"
Expand All @@ -59,7 +59,7 @@
# 1. Cold-deploy the certificates to haproxy's certs directory
# 2. Make sure haproxy is started, and hot-deploy the certificates to haproxy though the socket API

- name: Cold-deploy the certificates to haproxy # noqa: no-handler
- name: "Cold-deploy the certificates to haproxy" # noqa: no-handler
ansible.builtin.command:
cmd: |
/home/acme/.acme.sh/acme.sh
Expand All @@ -75,20 +75,20 @@
become_user: "acme"
become: true

- name: Start and enable haproxy
- name: "Start and enable haproxy"
ansible.builtin.service:
name: "haproxy"
state: "started"
enabled: true

- name: Wait for port 443 to become open # noqa: no-handler
- name: "Wait for port 443 to become open" # noqa: no-handler
ansible.builtin.wait_for:
port: 443
delay: 5
host: "{{ haproxy_sni_ip.ipv4 }}"
when: "acme_issue.changed"

- name: Hot-deploy the certificates to haproxy # noqa: no-handler
- name: "Hot-deploy the certificates to haproxy" # noqa: no-handler
ansible.builtin.command:
cmd: |
/home/acme/.acme.sh/acme.sh
Expand Down