Skip to content

Commit

Permalink
Copy TLS certificate to the newly added nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
klention committed Dec 18, 2024
1 parent 4412bd1 commit 3097f7a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
16 changes: 16 additions & 0 deletions automation/add_pgnode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
- firewall_enabled_at_boot | bool
tags: firewall

- name: Fetch TLS certificate

Check warning on line 108 in automation/add_pgnode.yml

View workflow job for this annotation

GitHub Actions / build

jinja[spacing]

Jinja2 spacing could be improved: tls_cert_generate|bool -> tls_cert_generate | bool
ansible.builtin.include_role:
name: tls_certificate
tasks_from: copy_certificate
vars:
tls_job: fetch
when: tls_cert_generate|bool

roles:
- role: ansible-role-firewall
environment: "{{ proxy_env | default({}) }}"
Expand Down Expand Up @@ -228,6 +236,14 @@
ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml"
tags: always

- name: Copy TLS certificate

Check warning on line 239 in automation/add_pgnode.yml

View workflow job for this annotation

GitHub Actions / build

jinja[spacing]

Jinja2 spacing could be improved: tls_cert_generate|bool -> tls_cert_generate | bool
ansible.builtin.include_role:
name: tls_certificate
tasks_from: copy_certificate
vars:
tls_job: copy
when: tls_cert_generate|bool

roles:
- role: wal-g
when: wal_g_install|bool
Expand Down
47 changes: 47 additions & 0 deletions automation/roles/tls_certificate/tasks/copy_certificate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
- name: Fetch TLS certificate and key
run_once: true
ansible.builtin.fetch:
src: "{{ item }}"
dest: "/tmp/tls/"
flat: yes

Check warning on line 7 in automation/roles/tls_certificate/tasks/copy_certificate.yml

View workflow job for this annotation

GitHub Actions / build

7:11 [truthy] truthy value should be one of [false, true]

Check failure on line 7 in automation/roles/tls_certificate/tasks/copy_certificate.yml

View workflow job for this annotation

GitHub Actions / build

yaml[truthy]

Truthy value should be one of [false, true]
loop:
- "{{ tls_privatekey_path | default('/etc/tls/server.key') }}"
- "{{ tls_cert_path | default('/etc/tls/server.crt') }}"
when:
- tls_job is defined
- tls_job == 'fetch'

- block:
- name: Ensure TLS directories exist

Check failure on line 16 in automation/roles/tls_certificate/tasks/copy_certificate.yml

View workflow job for this annotation

GitHub Actions / build

16:3 [indentation] wrong indentation: expected 4 but found 2

Check failure on line 16 in automation/roles/tls_certificate/tasks/copy_certificate.yml

View workflow job for this annotation

GitHub Actions / build

yaml[indentation]

Wrong indentation: expected 4 but found 2
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ tls_owner | default('postgres') }}"
group: "{{ tls_owner | default('postgres') }}"
mode: "0750"
loop:
- "{{ tls_privatekey_path | default('/etc/tls/server.key') | dirname }}"
- "{{ tls_cert_path | default('/etc/tls/server.crt') | dirname }}"

- name: Copy TLS certificate and key to the new node
ansible.builtin.copy:
src: "/tmp/tls/{{ item | basename }}"
dest: "{{ item }}"
loop:
- "{{ tls_privatekey_path | default('/etc/tls/server.key') }}"
- "{{ tls_cert_path | default('/etc/tls/server.crt') }}"

- name: Set proper permissions for TLS files
ansible.builtin.file:
path: "{{ item.path }}"
owner: "{{ tls_owner | default('postgres') }}"
group: "{{ tls_owner | default('postgres') }}"
mode: "{{ item.mode }}"
state: file
loop:
- { path: "{{ tls_privatekey_path | default('/etc/tls/server.key') }}", mode: "0400" }
- { path: "{{ tls_cert_path | default('/etc/tls/server.crt') }}", mode: "0644" }
when:
- tls_job is defined
- tls_job == 'copy'

0 comments on commit 3097f7a

Please sign in to comment.