Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure old ssl certs not copied in nginx role #149

Merged
merged 17 commits into from
Dec 4, 2024
Merged
Changes from 4 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
42 changes: 40 additions & 2 deletions roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,59 @@
mode: "0700"
when: nginx_use_ssl

- name: Copy server certificates to nginx
- name: Get current SSL certificate info
community.crypto.x509_certificate_info:
path: "{{ nginx_ssl_cert_file }}"
register: current_cert_info
ignore_errors: true # Handle case where file doesn't exist
when: nginx_use_ssl

- name: Get cached SSL certificate info
community.crypto.x509_certificate_info:
path: "{{ nginx_server_cert_cache }}"
register: cached_cert_info
when: nginx_use_ssl

- name: Copy server certificates from cache (if it has a later expiry) to nginx
ansible.builtin.copy:
remote_src: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ nginx_owner }}"
group: "{{ nginx_group }}"
mode: "0600"
backup: true # Preserve overwritten certificates and keys for rollback
with_items:
- src: "{{ nginx_server_cert_cache }}"
dest: "{{ nginx_ssl_cert_file }}"
- src: "{{ nginx_server_key_cache }}"
dest: "{{ nginx_ssl_key_file }}"
notify: Reload nginx
when: nginx_use_ssl
when:
- nginx_use_ssl
- current_cert_info.failed or (cached_cert_info.cert.not_after | to_datetime
> current_cert_info.cert.not_after | to_datetime)

- name:
Copy server certificates from nginx (if it has a later expiry) back to cache
ansible.builtin.copy:
remote_src: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ nginx_owner }}"
group: "{{ nginx_group }}"
mode: "0600"
backup: true # Preserve overwritten certificates and keys for rollback
with_items:
- src: "{{ nginx_ssl_cert_file }}"
dest: "{{ nginx_server_cert_cache }}"
- src: "{{ nginx_ssl_key_file }}"
dest: "{{ nginx_server_key_cache }}"
notify: Reload nginx
when:
- nginx_use_ssl
- (cached_cert_info.cert.not_after | to_datetime <
current_cert_info.cert.not_after | to_datetime)

- name:
Generate Diffie-Hellman (DH) parameters. Number of {{
Expand Down
Loading