Skip to content
This repository was archived by the owner on Jul 16, 2026. It is now read-only.
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
85 changes: 82 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@
- testing is defined
- letsencrypt_cert.stat.exists == False

- name: Create live directory for testing CA
file:
dest: /etc/letsencrypt/live/CA
state: directory
owner: root
group: root
mode: 0755
when:
- testing is defined
- letsencrypt_cert.stat.exists == False

- name: Install openssl
apt:
pkg: openssl
Expand All @@ -72,18 +83,86 @@
- testing is defined
- letsencrypt_cert.stat.exists == False

- name: Create self-signed root certificate (CA), if testing.
command: >
openssl req -x509 -new -nodes -subj '/CN=lili' -days 30

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Why lili? ¿Couldn't it be anarres instad?

-newkey rsa:4096 -sha256 -keyout /etc/letsencrypt/live/CA/rootCA.key
-out /etc/letsencrypt/live/CA/rootCA.pem
args:
creates: /etc/letsencrypt/live/CA/rootCA.pem
ignore_errors: yes
when:
- testing is defined
- letsencrypt_cert.stat.exists == False
Comment on lines +89 to +96

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the condition letsencrypt_cert.stat.exists == False we're only checking that the cert for {{ domain }} exists so if the CA was already created this command is going to overwrite it. Even if it doesn't the condition must be related to the file it creates. You could use

args:
    creates: /path/to/file

in the command task so it's only executed if the rootCA.key doesn't already exist.


- name: Create self-signed certificate, if testing.
command: >
openssl req -x509 -nodes -subj '/CN={{ domain }}' -days 30
-newkey rsa:4096 -sha256 -keyout /etc/letsencrypt/live/{{ domain }}/privkey.pem
-out /etc/letsencrypt/live/{{ domain }}/cert.pem
openssl req -new -nodes -subj '/CN=lili' -days 30 \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the CN, maybe using the {{ domain }} is a better idea.

-newkey rsa:4096 -sha256 -keyout /etc/letsencrypt/live/{{ domain }}/privkey.pem \
-out /etc/letsencrypt/live/{{ domain }}/cert.csr
args:
creates: /etc/letsencrypt/live/{{ domain }}/cert.csr
ignore_errors: yes
when:
- testing is defined
- letsencrypt_cert.stat.exists == False

- name: Create X.509 v3 configuration file
template:
src: san_template.ext.j2
dest: "/etc/letsencrypt/live/{{ domain }}/{{ domain }}.ext"
ignore_errors: yes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Why?

when:
- testing is defined

- name: Create self-signed certificate, if testing.
command: >
openssl x509 -req -in /etc/letsencrypt/live/{{ domain }}/cert.csr
-CA /etc/letsencrypt/live/CA/rootCA.pem
-CAkey /etc/letsencrypt/live/CA/rootCA.key
-CAcreateserial -out /etc/letsencrypt/live/{{ domain }}/cert.pem
-days 30 -sha256 -extfile /etc/letsencrypt/live/{{ domain }}/{{ domain }}.ext
args:
creates: /etc/letsencrypt/live/{{ domain }}/cert.pem
ignore_errors: yes
when:
- testing is defined
- letsencrypt_cert.stat.exists == False

- name: Check if the certificate is on the system
stat:
path: "/usr/share/ca-certificates/extra/{{ base_domain }}.crt"
register: system_cert

- name: Create custom CA directory on system certificates
file:
dest: /usr/share/ca-certificates/extra
state: directory
owner: root
group: root
mode: 0755
when:
- testing is defined
- system_cert.stat.exists == False

- name: Add CA to system
copy:
src: /etc/letsencrypt/live/CA/rootCA.pem
dest: /usr/share/ca-certificates/extra/{{ base_domain }}.crt
remote_src: yes
ignore_errors: yes
when:
- testing is defined
- system_cert.stat.exists == False

- name: Update CA certificates on remote host.
command: >
update-ca-certificates
ignore_errors: yes
when:
- testing is defined
- system_cert.stat.exists == False

- name: Create a combined SSL cert for testing
shell: cat /etc/letsencrypt/live/{{ domain }}/cert.pem >
/etc/letsencrypt/live/{{ domain }}/fullchain.pem
Expand Down
7 changes: 7 additions & 0 deletions templates/san_template.ext.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = {{ domain }}
Comment on lines +1 to +7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Can you explain this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @acien101.