# Loop problem

**URL:** <https://forum.ansible.com/t/loop-problem/30110>\
**Category:** Ansible Project\
**Created:** [April 13, 2019, 5:47pm UTC](https://forum.ansible.com/t/loop-problem/30110 "2019-04-13T17:47:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sergio\_Fernandez](https://forum.ansible.com/u/Sergio_Fernandez)\
**Post date:** [April 13, 2019, 5:47pm UTC](https://forum.ansible.com/t/loop-problem/30110/1 "2019-04-13T17:47:17Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Sergio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sergio\_Fernandez](https://forum.ansible.com/u/Sergio_Fernandez)\
**Post date:** [April 13, 2019, 6:50pm UTC](https://forum.ansible.com/t/loop-problem/30110/2 "2019-04-13T18:50:07Z")

</div>

I’ve tried with another file, like this, without success:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 13, 2019, 6:54pm UTC](https://forum.ansible.com/t/loop-problem/30110/3 "2019-04-13T18:54:38Z")

</div>

Do you mean that you need to create a uniq secret for each server with the command  
vault write -f auth/approle/role/my\_role/secret-id -format=json | jq '.data.secret\_id' ?

Or create one secret that get sent to all the server?

---

<div class="post-metadata">

**Author:** ![Sergio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sergio\_Fernandez](https://forum.ansible.com/u/Sergio_Fernandez)\
**Post date:** [April 13, 2019, 9:53pm UTC](https://forum.ansible.com/t/loop-problem/30110/4 "2019-04-13T21:53:17Z")

</div>

Currently as the script is displayed, it creates 1 and send it all to all of the servers.  
But the requirements are to give each one its own secret\_id, so if I have 3 servers, I need to create 3 different secret\_id and send them!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 13, 2019, 10:08pm UTC](https://forum.ansible.com/t/loop-problem/30110/5 "2019-04-13T22:08:11Z")

</div>

Then you need to run both task for all the host and with delegate\_to you can run the task on localhost, but the variable will be registered on the remote host.

---

<div class="post-metadata">

**Author:** ![Sergio\_Fernandez](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sergio\_Fernandez](https://forum.ansible.com/u/Sergio_Fernandez)\
**Post date:** [April 14, 2019, 1:10pm UTC](https://forum.ansible.com/t/loop-problem/30110/6 "2019-04-14T13:10:07Z")

</div>

Didn’t know about that function! Thank you so much.
