|
| 1 | +--- |
| 2 | + |
| 3 | +# Copyright 2024 Cloudera, Inc. All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +- name: Pre - Initialization of local working directories |
| 18 | + hosts: localhost |
| 19 | + connection: local |
| 20 | + tasks: |
| 21 | + - name: Create temporary build directory |
| 22 | + ansible.builtin.tempfile: |
| 23 | + state: directory |
| 24 | + prefix: pvc_tls_ |
| 25 | + register: __pvc_tls_tempdir |
| 26 | + |
| 27 | + - name: Create a directory for csrs and signed certs |
| 28 | + ansible.builtin.file: |
| 29 | + path: "{{ [__pvc_tls_tempdir.path, item] | path_join }}" |
| 30 | + state: directory |
| 31 | + mode: '0755' |
| 32 | + loop: |
| 33 | + - csrs |
| 34 | + - certs |
| 35 | + - ca_certs |
| 36 | + |
| 37 | +- name: Play 1 - Generate CSR on each host |
| 38 | + hosts: "{{ target | default('cluster') }}" |
| 39 | + become: yes |
| 40 | + gather_facts: yes |
| 41 | + tasks: |
| 42 | + |
| 43 | + - name: Call tls_generate_csr role |
| 44 | + ansible.builtin.import_role: |
| 45 | + name: cloudera.exe.tls_generate_csr |
| 46 | + vars: |
| 47 | + local_csrs_dir: "{{ (hostvars['localhost']['__pvc_tls_tempdir']['path'], 'csrs') | path_join }}" |
| 48 | + |
| 49 | +- name: Get the list of CSRs to sign |
| 50 | + hosts: localhost |
| 51 | + connection: local |
| 52 | + tasks: |
| 53 | + - name: "Set fact for all CSRs in {{ local_csrs_dir }}" |
| 54 | + ansible.builtin.find: |
| 55 | + paths: "{{ local_csrs_dir }}" |
| 56 | + file_type: file |
| 57 | + register: __csrs_to_sign |
| 58 | + vars: |
| 59 | + local_csrs_dir: "{{ (hostvars['localhost']['__pvc_tls_tempdir']['path'], 'csrs') | path_join }}" |
| 60 | + |
| 61 | + - name: Set fact for csrs to sign |
| 62 | + ansible.builtin.set_fact: |
| 63 | + local_csrs_to_sign: "{{ __csrs_to_sign.files | json_query('[*].path') | flatten }}" |
| 64 | + |
| 65 | +- name: Play 2 - Sign the CSR |
| 66 | + hosts: ca_server |
| 67 | + become: yes |
| 68 | + gather_facts: yes |
| 69 | + tasks: |
| 70 | + |
| 71 | + - name: Call tls_signing role |
| 72 | + ansible.builtin.import_role: |
| 73 | + name: cloudera.exe.tls_signing |
| 74 | + vars: |
| 75 | + csrs_to_sign: "{{ hostvars['localhost']['local_csrs_to_sign'] }}" |
| 76 | + copy_from_controller: true |
| 77 | + local_certs_dir: "{{ (hostvars['localhost']['__pvc_tls_tempdir']['path'], 'certs') | path_join }}" |
| 78 | + |
| 79 | +- name: Play 3 - Install the sign certs on each host |
| 80 | + hosts: "{{ target | default('cluster') }}" |
| 81 | + become: yes |
| 82 | + gather_facts: yes |
| 83 | + tasks: |
| 84 | + |
| 85 | + - name: Call tls_install_certs role |
| 86 | + ansible.builtin.import_role: |
| 87 | + name: cloudera.exe.tls_install_certs |
| 88 | + vars: |
| 89 | + local_tls_signed_certs_dir: "{{ (hostvars['localhost']['__pvc_tls_tempdir']['path'], 'certs') | path_join }}" |
| 90 | + |
| 91 | +- name: Post 1 - Restart CM Server service |
| 92 | + hosts: cloudera_manager |
| 93 | + become: yes |
| 94 | + gather_facts: yes |
| 95 | + tasks: |
| 96 | + |
| 97 | + - name: Restart CM Server service |
| 98 | + when: |
| 99 | + - restart_services | default(False) |
| 100 | + ansible.builtin.service: |
| 101 | + name: cloudera-scm-server |
| 102 | + state: restarted |
| 103 | + |
| 104 | +- name: Post 2 - Restart DB Server service |
| 105 | + hosts: db_server |
| 106 | + become: yes |
| 107 | + gather_facts: yes |
| 108 | + tasks: |
| 109 | + |
| 110 | + - name: Restart DB Server service |
| 111 | + when: |
| 112 | + - restart_services | default(False) |
| 113 | + ansible.builtin.service: |
| 114 | + name: "{{ db_service_name }}" |
| 115 | + state: reloaded |
| 116 | + |
| 117 | +- name: Post 3 - Restart CM Agent service |
| 118 | + hosts: cluster |
| 119 | + become: yes |
| 120 | + gather_facts: yes |
| 121 | + tasks: |
| 122 | + |
| 123 | + - name: Restart CM Agent service |
| 124 | + when: |
| 125 | + - restart_services | default(False) |
| 126 | + ansible.builtin.service: |
| 127 | + name: cloudera-scm-agent |
| 128 | + state: restarted |
0 commit comments