blob: 14b12d615b6e2d7549597c5f1a15d0d1ccaab931 [file] [log] [blame]
Matteo Scandolo3896c472017-08-01 13:31:42 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Zack Williamsc047c872017-01-11 08:38:15 -070017---
18# pki-root-ca/tasks/main.yml
19
Zack Williams79286962017-07-10 12:24:37 -070020# if the next two steps fail, may need to include `create-configdirs-become`
21# role to create these directories using become.
Zack Williamsc989f262017-05-11 13:02:59 -070022- name: Create PKI and credentials directories
Zack Williams43d62b52017-01-23 07:34:45 -070023 file:
Zack Williamsc989f262017-05-11 13:02:59 -070024 dest: "{{ item }}"
Zack Williams43d62b52017-01-23 07:34:45 -070025 state: directory
26 owner: "{{ ansible_user_id }}"
27 mode: 0700
Zack Williamsc989f262017-05-11 13:02:59 -070028 with_items:
29 - "{{ credentials_dir }}"
30 - "{{ pki_dir }}"
Andy Bavier1cac0012017-03-13 10:06:18 -040031
Zack Williamsc047c872017-01-11 08:38:15 -070032- name: Create root CA directory
33 file:
34 dest: "{{ pki_dir }}/root_ca"
35 state: directory
Zack Williams43d62b52017-01-23 07:34:45 -070036 owner: "{{ ansible_user_id }}"
37 mode: 0755
Zack Williamsc047c872017-01-11 08:38:15 -070038
39- name: Create root CA openssl.cnf from template
40 template:
41 src: openssl_root.cnf.j2
42 dest: "{{ pki_dir }}/root_ca/openssl.cnf"
43 force: no
44
45- name: Create subdirs for root CA
46 file:
47 dest: "{{ pki_dir }}/root_ca/{{ item }}"
48 state: directory
Zack Williams43d62b52017-01-23 07:34:45 -070049 owner: "{{ ansible_user_id }}"
50 mode: 0755
Zack Williamsc047c872017-01-11 08:38:15 -070051 with_items:
52 - certs
53 - crl
54 - newcerts
55
56- name: Create private CA directory
57 file:
58 dest: "{{ pki_dir }}/root_ca/private"
59 state: directory
Zack Williams43d62b52017-01-23 07:34:45 -070060 owner: "{{ ansible_user_id }}"
Zack Williamsc047c872017-01-11 08:38:15 -070061 mode: 0700
62
63- name: Create serial file
64 copy:
65 dest: "{{ pki_dir }}/root_ca/serial"
66 content: "1000"
67 force: no
68
69- name: Create empty index file if it doesn't exist
70 copy:
71 dest: "{{ pki_dir }}/root_ca/index.txt"
72 content: ""
73 force: no
Zack Williams43d62b52017-01-23 07:34:45 -070074 owner: "{{ ansible_user_id }}"
75 mode: 0755
Zack Williamsc047c872017-01-11 08:38:15 -070076
77- name: Save root passphrase to root_ca/private/ca_root_phrase
78 copy:
79 dest: "{{ pki_dir }}/root_ca/private/ca_root_phrase"
80 content: "{{ ca_root_phrase }}"
Zack Williams43d62b52017-01-23 07:34:45 -070081 owner: "{{ ansible_user_id }}"
Zack Williamsc047c872017-01-11 08:38:15 -070082 mode: 0400
83
84- name: Generate root key
85 command: >
86 openssl genrsa -aes256
87 -out {{ pki_dir }}/root_ca/private/ca_key.pem
88 -passout file:{{ pki_dir }}/root_ca/private/ca_root_phrase
89 {{ ca_size }}
90 args:
91 creates: "{{ pki_dir }}/root_ca/private/ca_key.pem"
92
93- name: Set permissions on root key
94 file:
95 dest: "{{ pki_dir }}/root_ca/private/ca_key.pem"
Zack Williams43d62b52017-01-23 07:34:45 -070096 owner: "{{ ansible_user_id }}"
Zack Williamsc047c872017-01-11 08:38:15 -070097 mode: 0400
98
99- name: Create root certificate
100 command: >
101 openssl req -config {{ pki_dir }}/root_ca/openssl.cnf
102 -key {{ pki_dir }}/root_ca/private/ca_key.pem
103 -passin file:{{ pki_dir }}/root_ca/private/ca_root_phrase
104 -new -x509 -days {{ ca_root_days }}
105 -sha256 -extensions v3_ca
106 -subj "{{ ca_root_subj }}"
107 -out {{ pki_dir }}/root_ca/certs/ca_cert.pem
108 args:
109 creates: "{{ pki_dir }}/root_ca/certs/ca_cert.pem"