Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 1 | |
| 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 Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 17 | --- |
| 18 | # pki-root-ca/tasks/main.yml |
| 19 | |
Zack Williams | 7928696 | 2017-07-10 12:24:37 -0700 | [diff] [blame] | 20 | # if the next two steps fail, may need to include `create-configdirs-become` |
| 21 | # role to create these directories using become. |
Zack Williams | c989f26 | 2017-05-11 13:02:59 -0700 | [diff] [blame] | 22 | - name: Create PKI and credentials directories |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 23 | file: |
Zack Williams | c989f26 | 2017-05-11 13:02:59 -0700 | [diff] [blame] | 24 | dest: "{{ item }}" |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 25 | state: directory |
| 26 | owner: "{{ ansible_user_id }}" |
| 27 | mode: 0700 |
Zack Williams | c989f26 | 2017-05-11 13:02:59 -0700 | [diff] [blame] | 28 | with_items: |
| 29 | - "{{ credentials_dir }}" |
| 30 | - "{{ pki_dir }}" |
Andy Bavier | 1cac001 | 2017-03-13 10:06:18 -0400 | [diff] [blame] | 31 | |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 32 | - name: Create root CA directory |
| 33 | file: |
| 34 | dest: "{{ pki_dir }}/root_ca" |
| 35 | state: directory |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 36 | owner: "{{ ansible_user_id }}" |
| 37 | mode: 0755 |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 38 | |
| 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 Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 49 | owner: "{{ ansible_user_id }}" |
| 50 | mode: 0755 |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 51 | 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 Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 60 | owner: "{{ ansible_user_id }}" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 61 | 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 Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 74 | owner: "{{ ansible_user_id }}" |
| 75 | mode: 0755 |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 76 | |
| 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 Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 81 | owner: "{{ ansible_user_id }}" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 82 | 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 Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 96 | owner: "{{ ansible_user_id }}" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 97 | 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" |