Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 1 | --- |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 2 | # pki-intermediate-ca/tasks/main.yml |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 3 | |
Andy Bavier | 1cac001 | 2017-03-13 10:06:18 -0400 | [diff] [blame] | 4 | - name: Create PKI directory |
| 5 | become: yes |
| 6 | file: |
| 7 | dest: "{{ pki_dir }}" |
| 8 | state: directory |
| 9 | owner: "{{ ansible_user_id }}" |
| 10 | mode: 0755 |
| 11 | |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 12 | - name: Create intermediate CA directory |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 13 | become: yes |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 14 | file: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 15 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 16 | state: directory |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 17 | owner: "{{ ansible_user_id }}" |
| 18 | mode: 0755 |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 19 | |
| 20 | - name: Create intermediate CA openssl.cnf from template |
| 21 | template: |
| 22 | src: openssl_im.cnf.j2 |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 23 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/openssl.cnf" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 24 | force: no |
| 25 | |
| 26 | - name: Create subdirs for intermediate CA |
| 27 | file: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 28 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/{{ item }}" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 29 | state: directory |
| 30 | with_items: |
| 31 | - certs |
| 32 | - crl |
| 33 | - csr |
| 34 | - newcerts |
| 35 | |
| 36 | - name: Create private CA directory |
| 37 | file: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 38 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/private" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 39 | state: directory |
| 40 | mode: 0700 |
| 41 | |
| 42 | - name: Create serial file |
| 43 | copy: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 44 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/serial" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 45 | content: "01" |
| 46 | force: no |
| 47 | |
| 48 | - name: Create empty index file if it doesn't exist |
| 49 | copy: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 50 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/index.txt" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 51 | content: "" |
| 52 | force: no |
| 53 | |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 54 | - name: Save intermediate passphrase to sitename_im_ca/private/ca_im_phrase |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 55 | copy: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 56 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/private/ca_im_phrase" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 57 | content: "{{ ca_im_phrase }}" |
| 58 | mode: 0400 |
| 59 | |
| 60 | - name: Generate intermediate key |
| 61 | command: > |
| 62 | openssl genrsa -aes256 |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 63 | -out {{ pki_dir }}/{{ site_name }}_im_ca/private/im_key.pem |
| 64 | -passout file:{{ pki_dir }}/{{ site_name }}_im_ca/private/ca_im_phrase |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 65 | {{ ca_size }} |
| 66 | args: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 67 | creates: "{{ pki_dir }}/{{ site_name }}_im_ca/private/im_key.pem" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 68 | |
| 69 | - name: Set permissions on intermediate key |
| 70 | file: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 71 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/private/im_key.pem" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 72 | mode: 0400 |
| 73 | |
| 74 | - name: Create intermediate CSR |
| 75 | command: > |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 76 | openssl req -config {{ pki_dir }}/{{ site_name }}_im_ca/openssl.cnf |
| 77 | -key {{ pki_dir }}/{{ site_name }}_im_ca/private/im_key.pem |
| 78 | -passin file:{{ pki_dir }}/{{ site_name }}_im_ca/private/ca_im_phrase |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 79 | -new -sha256 -subj "{{ ca_im_subj }}" |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 80 | -out {{ pki_dir }}/{{ site_name }}_im_ca/csr/{{ site_name }}_im_ca_csr.pem |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 81 | args: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 82 | creates: "{{ pki_dir }}/{{ site_name }}_im_ca/certs/{{ site_name }}_im_ca_csr.pem" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 83 | environment: |
| 84 | KEY_ALTNAMES: "" |
| 85 | |
| 86 | - name: Create intermediate cert from CSR with root CA |
| 87 | command: > |
| 88 | openssl ca -config {{ pki_dir }}/root_ca/openssl.cnf -batch |
| 89 | -extensions v3_intermediate_ca |
| 90 | -passin file:{{ pki_dir }}/root_ca/private/ca_root_phrase |
| 91 | -days {{ ca_im_days }} -md {{ ca_digest }} |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 92 | -in {{ pki_dir }}/{{ site_name }}_im_ca/csr/{{ site_name }}_im_ca_csr.pem |
| 93 | -out {{ pki_dir }}/{{ site_name }}_im_ca/certs/im_cert.pem |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 94 | args: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 95 | creates: "{{ pki_dir }}/{{ site_name }}_im_ca/certs/im_cert.pem" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 96 | |
| 97 | - name: Verify intemediate cert |
| 98 | command: > |
| 99 | openssl verify |
| 100 | -CAfile {{ pki_dir }}/root_ca/certs/ca_cert.pem |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 101 | {{ pki_dir }}/{{ site_name }}_im_ca/certs/im_cert.pem |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 102 | register: im_verify |
| 103 | tags: |
| 104 | - skip_ansible_lint # diagnostic command |
| 105 | |
| 106 | - name: Assert that verify of intermediate cert succeeded |
| 107 | assert: |
| 108 | that: "'OK' in '{{ im_verify.stdout }}'" |
| 109 | |
| 110 | - name: Get the root cert into ca_cert var |
| 111 | command: > |
| 112 | openssl x509 -in {{ pki_dir }}/root_ca/certs/ca_cert.pem |
| 113 | register: ca_cert |
| 114 | tags: |
| 115 | - skip_ansible_lint # concat of files |
| 116 | |
| 117 | - name: Get the intermediate cert into im_cert var |
| 118 | command: > |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 119 | openssl x509 -in {{ pki_dir }}/{{ site_name }}_im_ca/certs/im_cert.pem |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 120 | register: im_cert |
| 121 | tags: |
| 122 | - skip_ansible_lint # concat of files |
| 123 | |
| 124 | - name: Create intermediate cert chain |
| 125 | copy: |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 126 | dest: "{{ pki_dir }}/{{ site_name }}_im_ca/certs/im_cert_chain.pem" |
Zack Williams | c047c87 | 2017-01-11 08:38:15 -0700 | [diff] [blame] | 127 | content: "{{ im_cert.stdout }}\n{{ ca_cert.stdout }}" |
Zack Williams | 44845c6 | 2017-04-21 13:57:14 -0700 | [diff] [blame] | 128 | |