generate private key on localhost

This commit is contained in:
histausse 2021-09-08 21:01:51 +02:00
parent 957f3e29ff
commit d01e17c4dd
Signed by: histausse
GPG key ID: 67486F107F62E9E9
2 changed files with 26 additions and 5 deletions

View file

@ -4,4 +4,5 @@
roles: roles:
- generate-cert - generate-cert
vars: vars:
path: /tmp/test-client directory: /tmp/test-pki
cname: test-client

View file

@ -3,10 +3,30 @@
ansible.builtin.debug: ansible.builtin.debug:
msg: "Test" msg: "Test"
- name: Ensure the directory containing the cert exist
file:
path: "{{ directory }}"
state: directory
- name: Test if the key already exist
stat:
path: "{{ directory }}/{{ cname }}.key"
register: key_file
- name: Generate private key - name: Generate private key
become: false
openssl_privatekey: openssl_privatekey:
path: "{{ path }}.key" path: "/tmp/ansible_hacky_pki_{{ cname }}.key"
owner: "{{ owner | default(omit) }}" mode: u=rw,g=,o=
group: "{{ group | default(omit) }}"
mode: "{{ key_mode | default(omit) }}"
size: "{{ key_size | default(omit) }}" size: "{{ key_size | default(omit) }}"
delegate_to: localhost
when: not key_file.stat.exists
- name: Send private key to the server
copy:
src: "/tmp/ansible_hacky_pki_{{ cname }}.key"
dest: "{{ directory }}/{{ cname }}.key"
owner: "{{ owner | default('root') }}"
group: "{{ group | default('root') }}"
mode: "{{ key_mode | default('u=rw,g=,o=') }}"
when: not key_file.stat.exists