Skip to content

Commit

Permalink
feat: generate csrs
Browse files Browse the repository at this point in the history
closes #14
  • Loading branch information
franklinkim committed Aug 18, 2017
1 parent 507a6b1 commit 0abb9d4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ openssl_self_signed: []
openssl_config: {}
# config template to install, relative to the ansible repository root
openssl_config_template:
# generate a CSR for each self signed certificate
openssl_generate_csr: no
# path to certificate signing requests
openssl_csrs_path: /etc/ssl/csrs
# should CAcert certificates be downloaded and added to the keyring?
openssl_cacert_import: no
# overrides for the file checksum when the CACert root certificates are downloaded.
Expand Down Expand Up @@ -146,6 +149,8 @@ This is an example playbook:
organizationName_default: 'My Organization'
organizationalUnitName_default: 'My Organization Unit'
commonName_default: 'foobar.com'
openssl_cacert_import: yes
openssl_generate_csr: yes
```

Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ openssl_self_signed: []
openssl_config: {}
# config template to install, relative to the ansible repository root
openssl_config_template:

# generate a CSR for each self signed certificate
openssl_generate_csr: no
# path to certificate signing requests
openssl_csrs_path: /etc/ssl/csrs
# should CAcert certificates be downloaded and added to the keyring?
openssl_cacert_import: no
# overrides for the file checksum when the CACert root certificates are downloaded.
Expand Down
8 changes: 8 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
vars:
item: "{{ openssl_keys_path }}"
mode: "0700"

- name: Creating csrs dir
when: openssl_generate_csr
include: create_dir.yml
vars:
item: "{{ openssl_csrs_path }}"
mode: "0750"

12 changes: 12 additions & 0 deletions tasks/manage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@
args:
creates: "{{ openssl_certs_path }}/{{ item.name }}.crt"
with_items: "{{ openssl_self_signed }}"

- name: Generating CSR from Certificate
when: openssl_generate_csr
command: >
openssl req -new
-subj "/C={{ item.country | default('') }}/ST={{ item.state | default('') }}/L={{ item.city | default('') }}/O={{ item.organization | default('') }}/OU={{ item.unit | default('') }}{% if item.domains is defined %}{% for domain in item.domains %}/CN={{ domain }}{% endfor %}{% else %}/CN={{ item.name }}{% endif %}/emailAddress={{ item.email | default('') }}"
-key {{ openssl_keys_path }}/{{ item.name }}.key
-out {{ openssl_csrs_path }}/{{ item.name }}.csr
args:
creates: "{{ openssl_csrs_path }}/{{ item.name }}.csr"
with_items: "{{ openssl_self_signed }}"

2 changes: 2 additions & 0 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
organizationName_default: 'My Organization'
organizationalUnitName_default: 'My Organization Unit'
commonName_default: 'foobar.com'
openssl_cacert_import: yes
openssl_generate_csr: yes

0 comments on commit 0abb9d4

Please sign in to comment.