Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 1 | --- |
| 2 | # pki-root-ca/tasks/main.yml |
| 3 | |
| 4 | - name: Create root CA directory |
| 5 | file: |
| 6 | dest: "{{ pki_dir }}/root_ca" |
| 7 | state: directory |
| 8 | |
| 9 | - name: Create root CA openssl.cnf from template |
| 10 | template: |
| 11 | src: openssl_root.cnf.j2 |
| 12 | dest: "{{ pki_dir }}/root_ca/openssl.cnf" |
| 13 | force: no |
| 14 | |
| 15 | - name: Create subdirs for root CA |
| 16 | file: |
| 17 | dest: "{{ pki_dir }}/root_ca/{{ item }}" |
| 18 | state: directory |
| 19 | with_items: |
| 20 | - certs |
| 21 | - crl |
| 22 | - newcerts |
| 23 | |
| 24 | - name: Create private CA directory |
| 25 | file: |
| 26 | dest: "{{ pki_dir }}/root_ca/private" |
| 27 | state: directory |
| 28 | mode: 0700 |
| 29 | |
| 30 | - name: Create serial file |
| 31 | copy: |
| 32 | dest: "{{ pki_dir }}/root_ca/serial" |
| 33 | content: "1000" |
| 34 | force: no |
| 35 | |
| 36 | - name: Create empty index file if it doesn't exist |
| 37 | copy: |
| 38 | dest: "{{ pki_dir }}/root_ca/index.txt" |
| 39 | content: "" |
| 40 | force: no |
| 41 | |
| 42 | - name: Save root passphrase to root_ca/private/ca_root_phrase |
| 43 | copy: |
| 44 | dest: "{{ pki_dir }}/root_ca/private/ca_root_phrase" |
| 45 | content: "{{ ca_root_phrase }}" |
| 46 | mode: 0400 |
| 47 | |
| 48 | - name: Generate root key |
| 49 | command: > |
| 50 | openssl genrsa -aes256 |
| 51 | -out {{ pki_dir }}/root_ca/private/ca_key.pem |
| 52 | -passout file:{{ pki_dir }}/root_ca/private/ca_root_phrase |
| 53 | {{ ca_size }} |
| 54 | args: |
| 55 | creates: "{{ pki_dir }}/root_ca/private/ca_key.pem" |
| 56 | |
| 57 | - name: Set permissions on root key |
| 58 | file: |
| 59 | dest: "{{ pki_dir }}/root_ca/private/ca_key.pem" |
| 60 | mode: 0400 |
| 61 | |
| 62 | - name: Create root certificate |
| 63 | command: > |
| 64 | openssl req -config {{ pki_dir }}/root_ca/openssl.cnf |
| 65 | -key {{ pki_dir }}/root_ca/private/ca_key.pem |
| 66 | -passin file:{{ pki_dir }}/root_ca/private/ca_root_phrase |
| 67 | -new -x509 -days {{ ca_root_days }} |
| 68 | -sha256 -extensions v3_ca |
| 69 | -subj "{{ ca_root_subj }}" |
| 70 | -out {{ pki_dir }}/root_ca/certs/ca_cert.pem |
| 71 | args: |
| 72 | creates: "{{ pki_dir }}/root_ca/certs/ca_cert.pem" |
| 73 | |