Hi,
I am using Ansible along with HashiCorp's Vault to store sensible data.
I will be weekly sending a Secret_ID to each server, in order for them to get a token. With this token, they can access the contents of the Vault.
The problem is that we must send a secret ID per host, and they can only be generated in the server where Ansible is installed.
So here is my current Ansible Playbook file:
---
- hosts: localhost
gather_facts: no
tasks:
- name: Generate secret_id
shell: vault write -f auth/approle/role/my_role/secret-id -format=json | jq '.data.secret_id'
register: secret_id
- set_fact:
secret_id_clean: "{{ secret_id.stdout | replace('\"', '') | replace('\','') }}"
- hosts: MyServers
gather_facts: no
tasks:
- name: Get Approle Token
shell: source /etc/profile && vault write auth/approle/login role_id=$VAULT_ROLE_ID secret_id="{{ hostvars['localhost']['secret_id_clean'] }}" -format=json | jq '.auth.client_token'
args:
executable: /bin/bash
register: token
- set_fact:
token_clean: "{{ token.stdout | replace('\"', '') | replace('\','') }}"
in hosts file:
[MyServers]
1.1.1.1
2.2.2.2
3.3.3.3