---

- name: bootstrap/gen_auth_ca | Generate Root CA
  uri:
    url: "{{ vault_leader_url }}/v1/auth-pki/root/generate/exported"
    headers: "{{ vault_headers }}"
    method: POST
    body_format: json
    body: "{{ vault_ca_options }}"
  register: vault_auth_ca_gen
  when: inventory_hostname == groups.vault|first

- name: bootstrap/gen_auth_ca | Copy auth CA cert to Vault nodes
  copy:
    content: "{{ hostvars[groups.vault|first]['vault_auth_ca_gen']['json']['data']['certificate'] }}"
    dest: "{{ vault_cert_dir }}/auth-ca.pem"

- name: bootstrap/gen_auth_ca | Copy auth CA key to Vault nodes
  copy:
    content: "{{ hostvars[groups.vault|first]['vault_auth_ca_gen']['json']['data']['private_key'] }}"
    dest: "{{ vault_cert_dir }}/auth-ca-key.pem"
