homelab/roles/nginx/tasks/self-signed.yml

42 lines
1.7 KiB
YAML
Raw Normal View History

2021-05-05 18:41:28 +00:00
- name: generate root ca
command: openssl req \
-x509 \
-new \
-nodes \
-newkey rsa:2048 \
2021-05-14 20:45:51 +00:00
-keyout "{{ playbook_dir }}/roles/nginx/files/rootca.key" \
-out "{{ playbook_dir }}/roles/nginx/files/rootca.pem" \
2021-05-05 18:41:28 +00:00
-sha256 \
-days 3650 \
-subj "/C=CZ/L=Prague/CN=Homelab/emailAddress={{ admin_email }}"
2021-05-14 20:45:51 +00:00
when: generate_cert.root
2021-05-05 18:41:28 +00:00
- name: generate wildcard csr
command: openssl req \
-new \
-nodes \
-newkey rsa:2048 \
2021-05-14 20:45:51 +00:00
-keyout "{{ playbook_dir }}/roles/nginx/files/{{ base_domain }}.key" \
-out "{{ playbook_dir }}/roles/nginx/files/{{ base_domain }}.csr" \
2021-05-05 18:41:28 +00:00
-subj "/C=CZ/L=Prague/CN=*.{{ base_domain }}/emailAddress={{ admin_email }}"
2021-05-14 20:45:51 +00:00
when: generate_cert.wildcard
2021-05-05 18:41:28 +00:00
- name: sign wildcard csr with root ca
command: openssl x509 \
-req \
2021-05-14 20:45:51 +00:00
-in "{{ playbook_dir }}/roles/nginx/files/{{ base_domain }}.csr" \
-CA "{{ playbook_dir }}/roles/nginx/files/rootca.pem" \
-CAkey "{{ playbook_dir }}/roles/nginx/files/rootca.key" \
2021-05-05 18:41:28 +00:00
-CAcreateserial \
2021-05-14 20:45:51 +00:00
-out "{{ playbook_dir }}/roles/nginx/files/{{ base_domain }}.crt" \
2021-05-05 18:41:28 +00:00
-days 3650 \
-sha256
2021-05-14 20:45:51 +00:00
when: generate_cert.wildcard
- name: copy wildcard certificate and key from vault
2021-05-14 20:45:51 +00:00
copy:
content: "{{ item.content }}"
dest: "{{ data_folder }}/nginx/{{ item.name }}"
owner: root
group: root
2021-05-14 20:45:51 +00:00
mode: '0700'
with_items:
- "{{ certificates }}"
no_log: true