-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathca.yml
More file actions
89 lines (80 loc) · 3.17 KB
/
Copy pathca.yml
File metadata and controls
89 lines (80 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
- name: 'Check if CA certificate exists'
ansible.builtin.stat:
path: "{{ certificates_ca_directory_certs }}/ca.crt"
register: _certificates_ca_cert
- name: 'Check for an existing CA key'
ansible.builtin.stat:
path: "{{ certificates_ca_directory_keys }}/ca.key"
register: _certificates_existing_ca_key
- name: 'Detect whether the existing CA key is password-encrypted'
ansible.builtin.command:
cmd: "grep -q ENCRYPTED {{ certificates_ca_directory_keys }}/ca.key"
register: _certificates_ca_key_encrypted
changed_when: false
failed_when: false
when: _certificates_existing_ca_key.stat.exists
- name: 'Decrypt a legacy password-encrypted CA key in place'
community.crypto.openssl_privatekey_convert:
src_path: "{{ certificates_ca_directory_keys }}/ca.key"
src_passphrase: "{{ certificates_ca_password }}"
dest_path: "{{ certificates_ca_directory_keys }}/ca.key"
format: pkcs8
mode: '0600'
when:
- _certificates_existing_ca_key.stat.exists
- (_certificates_ca_key_encrypted.rc | default(1)) == 0
no_log: true
- name: 'Remove the obsolete CA key password file'
ansible.builtin.file:
path: "{{ certificates_ca_directory_keys }}/ca.pwd"
state: absent
- name: 'Generate CA'
when:
- (not _certificates_ca_cert.stat.exists or certificates_renew_ca)
block:
- name: 'Create CA private key'
community.crypto.openssl_privatekey:
path: "{{ certificates_ca_directory_keys }}/ca.key"
type: "{{ certificates_algorithm_type }}"
size: "{{ certificates_algorithm_size }}"
owner: root
group: root
mode: '0600'
- name: 'Create CA certificate signing request'
community.crypto.openssl_csr:
path: "{{ certificates_ca_directory_requests }}/ca.csr"
privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key"
common_name: "{{ certificates_ca_subject }}"
use_common_name_for_san: false
basic_constraints:
- 'CA:TRUE'
basic_constraints_critical: true
key_usage:
- keyCertSign
- cRLSign
- digitalSignature
key_usage_critical: true
create_subject_key_identifier: true
- name: 'Create self-signed CA certificate'
community.crypto.x509_certificate:
path: "{{ certificates_ca_directory_certs }}/ca.crt"
csr_path: "{{ certificates_ca_directory_requests }}/ca.csr"
privatekey_path: "{{ certificates_ca_directory_keys }}/ca.key"
provider: selfsigned
selfsigned_not_after: "+{{ certificates_ca_validity_days }}d"
force: "{{ certificates_renew_ca | bool }}"
- name: 'Copy CA as server CA certificate'
ansible.builtin.copy:
src: "{{ certificates_ca_directory_certs }}/ca.crt"
dest: "{{ certificates_ca_directory_certs }}/server-ca.crt"
remote_src: true
force: "{{ certificates_renew_ca | bool }}"
mode: '0444'
- name: 'Create CA bundle'
ansible.builtin.copy:
src: "{{ certificates_ca_directory_certs }}/ca.crt"
dest: "{{ certificates_ca_directory_certs }}/ca-bundle.crt"
remote_src: true
force: "{{ certificates_renew_ca | bool }}"
mode: '0444'