Skip to content

Add playbook for updating Vault API TLS certificate #1377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: stackhpc/2024.1
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions etc/kayobe/ansible/vault-update-api-cert-overcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
- name: Update Overcloud Vault API certificate
any_errors_fatal: true
gather_facts: true
hosts: seed
vars:
consul_bind_interface: "lo"
vault_bind_address: "{{ ansible_facts[consul_bind_interface].ipv4.address }}"
vault_api_addr: "http://{{ vault_bind_address }}:8200"
tasks:
- name: Set a fact about the virtualenv on the remote system
set_fact:
virtualenv: "{{ ansible_python_interpreter | dirname | dirname }}"
when:
- ansible_python_interpreter is defined
- not ansible_python_interpreter.startswith('/bin/')
- not ansible_python_interpreter.startswith('/usr/bin/')

- name: Ensure Python PyYAML and hvac modules are installed
pip:
name:
- PyYAML
- hvac
state: latest
extra_args: "{% if pip_upper_constraints_file %}-c {{ pip_upper_constraints_file }}{% endif %}"
virtualenv: "{{ virtualenv is defined | ternary(virtualenv, omit) }}"
become: "{{ virtualenv is not defined }}"

- name: Ensure vault directory exists in Kayobe configuration
file:
path: "{{ kayobe_env_config_path }}/vault/"
state: directory
delegate_to: localhost
run_once: true

- name: Include Vault keys
include_vars:
file: "{{ kayobe_env_config_path }}/vault/seed-vault-keys.json"
name: vault_keys

- import_role:
name: stackhpc.hashicorp.vault_pki
vars:
vault_token: "{{ vault_keys.root_token }}"
vault_pki_root_create: false
vault_pki_intermediate_create: false
vault_pki_certificates_directory: "{{ kayobe_env_config_path }}/vault"
vault_pki_generate_certificates: true
vault_pki_write_certificates: true
vault_pki_certificate_subject:
- common_name: "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}"
role: "{{ seed_vault_pki_role_name }}"
extra_params:
ip_sans: "{% for host in groups['controllers'] %}{{ internal_net_name | net_ip(host) }}{% if not loop.last %},{% endif %}{% endfor %},{{ kolla_internal_vip_address }}"
vault_pki_write_certificate_files: true
vault_pki_overwrite_certificates: true
vault_pki_write_pem_bundle: false

- name: Copy new certificate and key to hosts
any_errors_fatal: true
gather_facts: true
hosts: controllers
tasks:
- name: Template out TLS key and cert
copy:
# Within the Hashicorp Vault container these uids & gids map to the vault user
src: "{{ kayobe_env_config_path }}/vault/{{ item }}"
dest: "/opt/kayobe/vault/{{ item }}"
owner: 100
group: 1000
mode: 0600
loop:
- "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.crt"
- "{% if kolla_internal_fqdn != kolla_internal_vip_address %}{{ kolla_internal_fqdn }}{% else %}overcloud{% endif %}.key"
become: True

- name: Restart Overcloud Vaults

Check failure on line 77 in etc/kayobe/ansible/vault-update-api-cert-overcloud.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.16 lint with Python 3.12

syntax-check[specific]

A malformed block was encountered while loading tasks: {'community.docker.docker_container': {'name': 'vault', 'state': 'started', 'restart': True}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>

Check failure on line 77 in etc/kayobe/ansible/vault-update-api-cert-overcloud.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.15 lint with Python 3.10

syntax-check[specific]

A malformed block was encountered while loading tasks: {'community.docker.docker_container': {'name': 'vault', 'state': 'started', 'restart': True}} should be a list or None but is <class 'ansible.parsing.yaml.objects.AnsibleMapping'>
any_errors_fatal: true
gather_facts: true
hosts: controllers
serial: 1
tasks:
community.docker.docker_container:
name: vault
state: started
restart: true

- name: Unseal Overcloud Vaults
import_playbook: "{{ kayobe_config_path }}/ansible/vault-unseal-overcloud.yml"
Loading