Ansible playbook to generate or get a certificate from AWS Amazon Certificate Manager (ACM)
- It assumes the Route53 zone for your domain exists in the current AWS account
- Requires community.aws (ansible-galaxy collection install community.aws). This is for Route53
- You must set certificate_region variable to the region you wish to use (e.g. eu-west-1)
- You must set validation_domain to the domain you wish to use for validation (e.g. yoursite.com)
- You must set certificate_domain to the domain you wish to issue a certificate for (e.g. api.yoursite.com)
- hosts: localhost
connection: local
gather_facts: False
vars_files:
- group_vars/all.yml
vars:
foo: "bar"
tasks:
- include: "roles/clusters/tasks/foo-bar.yml"
- name: Settings for regional ACM Certificate
set_fact:
certificate_region: "{{ ec2_region }}"
validation_domain: "{{ ec2_domain_name }}"
certificate_domain: "{{ my_vars.GUIDomainPrefix }}.{{ ec2_domain_name }}"
- include: "roles/clusters/tasks/get-acm-certificate.yml"
- name: Store regional certificate ARN
set_fact:
regional_certificate_arn: "{{ certificate_arn }}"
- include: "roles/clusters/tasks/baz-bat.yml"
Procedure is thus:
- Try to get the ISSUED certificate, if one exists
- Try to get the PENDING_VALIDATION certificate, if one exists
- Request a new certificate if we don't have one at all
- Wait for certificate DNS record to be made available
- Create Route53 DNS record for the certificate
- Wait for certificate to be validated
The playbook will set and log the certificate_arn fact. This is the ARN of the certificate that was found or generated