ansible_hacky_pki/roles/generate-cert/tasks/main.yml

33 lines
836 B
YAML
Raw Normal View History

2021-09-08 15:59:32 +02:00
---
- name: Test
ansible.builtin.debug:
msg: "Test"
2021-09-08 21:01:51 +02:00
- 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
2021-09-08 21:01:51 +02:00
become: false
openssl_privatekey:
2021-09-08 21:01:51 +02:00
path: "/tmp/ansible_hacky_pki_{{ cname }}.key"
mode: u=rw,g=,o=
size: "{{ key_size | default(omit) }}"
2021-09-08 21:01:51 +02:00
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