|
| 1 | +--- |
| 2 | +# Required for uri module to work with self-signed certificates and for systems to trust |
| 3 | +# the self-signed CA |
| 4 | +- name: Install CA on controllers |
| 5 | + hosts: controllers |
| 6 | + tasks: |
| 7 | + - name: Copy the intermediate CA |
| 8 | + ansible.builtin.copy: |
| 9 | + src: "{{ kayobe_env_config_path }}/{{ stackhpc_ca_secret_store }}/OS-TLS-ROOT.pem" |
| 10 | + dest: "{{ '/etc/pki/ca-trust/source/anchors/OS-TLS-ROOT.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' |
| 11 | + }}" |
| 12 | + mode: "0644" |
| 13 | + become: true |
| 14 | + |
| 15 | + - name: Update system CA |
| 16 | + become: true |
| 17 | + ansible.builtin.command: "{{ 'update-ca-trust' if ansible_facts.os_family == 'RedHat' else 'update-ca-certificates' }}" |
| 18 | + |
| 19 | +- name: Deploy Secret store on the overcloud |
| 20 | + any_errors_fatal: true |
| 21 | + gather_facts: true |
| 22 | + hosts: controllers |
| 23 | + vars: |
| 24 | + secret_store_bind_interface: "{{ internal_net_name | net_interface }}" |
| 25 | + secret_store_bind_address: "{{ internal_net_name | net_ip }}" |
| 26 | + # This is the IP address of the first controller and therefore the leader within |
| 27 | + # OpenBao. This could be replaced with the VIP address of the internal network if |
| 28 | + # HAProxy has been configured to load balance the OpenBao API. |
| 29 | + openbao_raft_leaders: |
| 30 | + - "{{ internal_net_name | net_ip(inventory_hostname=groups['controllers'][0]) }}" |
| 31 | + tasks: |
| 32 | + - name: Set a fact about the virtualenv on the remote system |
| 33 | + ansible.builtin.set_fact: |
| 34 | + virtualenv: "{{ ansible_python_interpreter | dirname | dirname }}" |
| 35 | + when: |
| 36 | + - ansible_python_interpreter is defined |
| 37 | + - not ansible_python_interpreter.startswith('/bin/') |
| 38 | + - not ansible_python_interpreter.startswith('/usr/bin/') |
| 39 | + |
| 40 | + - name: Ensure Python hvac module is installed |
| 41 | + ansible.builtin.pip: |
| 42 | + name: hvac |
| 43 | + state: latest |
| 44 | + extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}" |
| 45 | + virtualenv: "{{ virtualenv is defined | ternary(virtualenv, omit) }}" |
| 46 | + become: "{{ virtualenv is not defined }}" |
| 47 | + |
| 48 | + - name: Ensure /opt/kayobe/{{ stackhpc_ca_secret_store }} exists |
| 49 | + ansible.builtin.file: |
| 50 | + path: /opt/kayobe/{{ stackhpc_ca_secret_store }} |
| 51 | + state: directory |
| 52 | + |
| 53 | + - name: Template out TLS key and cert |
| 54 | + ansible.builtin.copy: |
| 55 | + # Within the OpenBao container these uids & gids map to the openbao user |
| 56 | + src: "{{ kayobe_env_config_path }}/{{ stackhpc_ca_secret_store }}/{{ item }}" |
| 57 | + dest: /opt/kayobe/{{ stackhpc_ca_secret_store }}/{{ item }} |
| 58 | + owner: 100 |
| 59 | + group: 1000 |
| 60 | + mode: "0600" |
| 61 | + loop: |
| 62 | + - "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.crt" |
| 63 | + - "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.key" |
| 64 | + - "OS-TLS-INT.crt" |
| 65 | + become: true |
| 66 | + |
| 67 | + - name: Apply vault role |
| 68 | + ansible.builtin.import_role: |
| 69 | + name: stackhpc.hashicorp.vault |
| 70 | + vars: |
| 71 | + hashicorp_registry_url: "{{ overcloud_hashicorp_registry_url }}" |
| 72 | + hashicorp_registry_username: "{{ overcloud_hashicorp_registry_username }}" |
| 73 | + hashicorp_registry_password: "{{ overcloud_hashicorp_registry_password }}" |
| 74 | + consul_docker_image: "{{ overcloud_consul_docker_image }}" |
| 75 | + consul_docker_tag: "{{ overcloud_consul_docker_tag }}" |
| 76 | + consul_bind_interface: "{{ secret_store_bind_interface }}" |
| 77 | + vault_bind_address: "{{ secret_store_bind_address }}" |
| 78 | + vault_config_dir: /opt/kayobe/vault |
| 79 | + vault_cluster_name: overcloud |
| 80 | + vault_ca_cert: "{{ '/etc/pki/tls/certs/ca-bundle.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' }}" |
| 81 | + vault_docker_image: "{{ overcloud_vault_docker_image }}" |
| 82 | + vault_docker_tag: "{{ overcloud_vault_docker_tag }}" |
| 83 | + vault_tls_cert: "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.crt" |
| 84 | + vault_tls_key: "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.key" |
| 85 | + copy_self_signed_ca: true |
| 86 | + vault_api_addr: https://{{ internal_net_name | net_ip }}:8200 |
| 87 | + vault_write_keys_file: true |
| 88 | + vault_write_keys_file_path: "{{ kayobe_env_config_path }}/vault/overcloud-vault-keys.json" |
| 89 | + when: stackhpc_ca_secret_store == "vault" |
| 90 | + |
| 91 | + - name: Apply OpenBao role |
| 92 | + ansible.builtin.import_role: |
| 93 | + name: stackhpc.hashicorp.openbao |
| 94 | + vars: |
| 95 | + openbao_bind_addr: "{{ secret_store_bind_address }}" |
| 96 | + openbao_registry_url: "{{ overcloud_openbao_registry_url }}" |
| 97 | + openbao_registry_username: "{{ overcloud_openbao_registry_username }}" |
| 98 | + openbao_registry_password: "{{ overcloud_openbao_registry_password }}" |
| 99 | + openbao_config_dir: /opt/kayobe/openbao |
| 100 | + openbao_cluster_name: overcloud |
| 101 | + openbao_ca_cert: "{{ '/etc/pki/tls/certs/ca-bundle.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' }}" |
| 102 | + openbao_docker_image: "{{ overcloud_openbao_docker_image }}" |
| 103 | + openbao_docker_tag: "{{ overcloud_openbao_docker_tag }}" |
| 104 | + openbao_tls_cert: "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.crt" |
| 105 | + openbao_tls_key: "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.key" |
| 106 | + openbao_tls_ca: "OS-TLS-INT.crt" |
| 107 | + copy_self_signed_ca: true |
| 108 | + openbao_api_addr: https://{{ internal_net_name | net_ip }}:8200 |
| 109 | + openbao_write_keys_file: true |
| 110 | + openbao_write_keys_file_path: "{{ kayobe_env_config_path }}/openbao/overcloud-openbao-keys.json" |
| 111 | + when: stackhpc_ca_secret_store == "openbao" |
| 112 | + |
| 113 | + - name: Include secret store keys |
| 114 | + ansible.builtin.include_vars: |
| 115 | + file: "{{ kayobe_env_config_path }}/{{ stackhpc_ca_secret_store }}/overcloud-{{ stackhpc_ca_secret_store }}-keys.json" |
| 116 | + name: secret_store_keys |
| 117 | + |
| 118 | + - name: Unseal first secret store instance |
| 119 | + ansible.builtin.import_role: |
| 120 | + name: stackhpc.hashicorp.vault_unseal |
| 121 | + vars: |
| 122 | + vault_api_addr: https://{{ internal_net_name | net_ip }}:8200 |
| 123 | + vault_unseal_token: "{{ secret_store_keys.root_token }}" |
| 124 | + vault_unseal_ca_cert: "{{ '/etc/pki/tls/certs/ca-bundle.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' }}" |
| 125 | + vault_unseal_keys: "{{ secret_store_keys.keys_base64 }}" |
| 126 | + environment: |
| 127 | + https_proxy: "" |
| 128 | + run_once: true |
| 129 | + |
| 130 | + # As the first instance is now unsealed the other instances will now need some |
| 131 | + # time to connect before we can proceed. |
| 132 | + - name: Wait for OpenBao Raft peers to connect |
| 133 | + ansible.builtin.wait_for: |
| 134 | + timeout: 30 |
| 135 | + delegate_to: localhost |
| 136 | + |
| 137 | + # Raft peers take few seconds before they report an unsealed state therefore |
| 138 | + # we must wait. |
| 139 | + - name: Unseal all secret store instances |
| 140 | + ansible.builtin.import_role: |
| 141 | + name: stackhpc.hashicorp.vault_unseal |
| 142 | + vars: |
| 143 | + vault_api_addr: https://{{ internal_net_name | net_ip }}:8200 |
| 144 | + vault_unseal_token: "{{ secret_store_keys.root_token }}" |
| 145 | + vault_unseal_ca_cert: "{{ '/etc/pki/tls/certs/ca-bundle.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' }}" |
| 146 | + vault_unseal_keys: "{{ secret_store_keys.keys_base64 }}" |
| 147 | + vault_unseal_timeout: 10 |
| 148 | + environment: |
| 149 | + https_proxy: "" |
| 150 | + |
| 151 | +- name: Configure PKI |
| 152 | + any_errors_fatal: true |
| 153 | + gather_facts: true |
| 154 | + hosts: controllers[0] |
| 155 | + tasks: |
| 156 | + - name: Apply pki role |
| 157 | + ansible.builtin.import_role: |
| 158 | + name: stackhpc.hashicorp.vault_pki |
| 159 | + vars: |
| 160 | + vault_token: "{{ secret_store_keys.root_token }}" |
| 161 | + vault_api_addr: https://{{ internal_net_name | net_ip }}:8200 |
| 162 | + vault_ca_cert: "{{ '/etc/pki/tls/certs/ca-bundle.crt' if ansible_facts.os_family == 'RedHat' else '/usr/local/share/ca-certificates/OS-TLS-ROOT.crt' }}" |
| 163 | + vault_pki_root_create: false |
| 164 | + vault_pki_intermediate_import: true |
| 165 | + vault_pki_intermediate_ca_name: OS-TLS-INT |
| 166 | + vault_pki_intermediate_ca_bundle: "{{ lookup('file', kayobe_env_config_path + '/' + stackhpc_ca_secret_store + '/OS-TLS-INT.pem') }}" |
| 167 | + vault_pki_intermediate_ca_cert: "{{ lookup('file', kayobe_env_config_path + '/' + stackhpc_ca_secret_store + '/OS-TLS-INT.crt') }}" |
| 168 | + vault_pki_intermediate_roles: "{{ overcloud_vault_pki_roles if stackhpc_ca_secret_store == 'vault' else overcloud_openbao_pki_roles }}" |
| 169 | + vault_pki_write_certificate_files: true |
| 170 | + vault_pki_certificates_directory: "{{ kayobe_env_config_path }}/{{ stackhpc_ca_secret_store }}" |
| 171 | + environment: |
| 172 | + https_proxy: "" |
0 commit comments