Skip to content

Commit

Permalink
Re-use recipes for certificate signing in vrouter and standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
valtri committed Oct 4, 2019
1 parent 5749f3a commit a19811b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 63 deletions.
44 changes: 44 additions & 0 deletions tasks/openssl_remote_sign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- name: Fetch CSR
fetch:
src: "{{ INDIGOVR_CERT_DIR }}/{{ INDIGOVR_CERT_NAME }}.csr"
dest: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
flat: yes
fail_on_missing: yes

- name: Copy CSR to CA
copy:
src: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
dest: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Check certfile stat
stat:
path: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
register: certfile
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Check csr stat
stat:
path: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr"
register: csrfile
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- block:
- name: Revoke previous certificate
command: openssl ca -config "{{ INDIGOVR_CA_DIR }}/openssl.cnf" -revoke "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
- name: Delete previous certificate
command: rm -fv "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
when: certfile.stat.exists and certfile.stat.mtime < csrfile.stat.mtime
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Sign certificate
shell: openssl ca -config "{{ INDIGOVR_CA_DIR }}/openssl.cnf" -extensions usr_cert -notext -batch -in "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr" -out "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
args:
creates: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

45 changes: 2 additions & 43 deletions tasks/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,8 @@
- name: CSR
include: openssl_csr.yml

- name: Fetch CSR
fetch:
src: "{{ INDIGOVR_CERT_DIR }}/{{ INDIGOVR_CERT_NAME }}.csr"
dest: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
flat: yes
fail_on_missing: yes

- name: Copy CSR to CA
copy:
src: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
dest: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Check certfile stat
stat:
path: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
register: certfile
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Check csr stat
stat:
path: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr"
register: csrfile
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- block:
- name: Revoke previous certificate
command: openssl ca -config "{{ INDIGOVR_CA_DIR }}/openssl.cnf" -revoke "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
- name: Delete previous certificate
command: rm -fv "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
when: certfile.stat.exists and certfile.stat.mtime < csrfile.stat.mtime
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Sign certificate
shell: openssl ca -config "{{ INDIGOVR_CA_DIR }}/openssl.cnf" -extensions usr_cert -notext -batch -in "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr" -out "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
args:
creates: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true
- name: Remote sign
include: openssl_remote_sign.yml

- name: Create client configuration
template:
Expand Down
22 changes: 2 additions & 20 deletions tasks/vrouter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@
- name: CSR
include: openssl_csr.yml

- name: Fetch CSR
fetch:
src: "{{ INDIGOVR_CERT_DIR }}/{{ INDIGOVR_CERT_NAME }}.csr"
dest: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
flat: yes
fail_on_missing: yes

- name: Copy CSR to CA
copy:
src: "/tmp/._indigovr_tmp_{{ INDIGOVR_CERT_NAME }}.csr"
dest: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true

- name: Sign certificate
shell: openssl ca -config "{{ INDIGOVR_CA_DIR }}/openssl.cnf" -extensions usr_cert -notext -batch -in "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.csr" -out "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
args:
creates: "{{ INDIGOVR_CA_DIR }}/certs/{{ INDIGOVR_CERT_NAME }}.crt"
delegate_to: "{{ INDIGOVR_CENTRALPOINT_IP }}"
become: true
- name: Remote sign
include: openssl_remote_sign.yml

- name: Create client configuration
template:
Expand Down

0 comments on commit a19811b

Please sign in to comment.