title: Working with ansible's variables, lists and dicts
body: <p>I want to deploy sensitive data using ansible-vault. Basically I want to iterate through every repository, iterate through its config files looking for secrets kept in the vault and replace them with the encrypted value in the vault. I want to pass the values of repositories as a variable to look through the secrets but keep getting errors.</p>
  <p>I tried various approaches but I'm unsure how to work with these data structures.<br />
  Advice is very appreciated.</p>
  <p>My code structure:</p>
  <pre class="lang-yaml prettyprint-override"><code>vars:
    repositories: [&quot;service1&quot;, &quot;service2&quot;]
    service1:
      service1.conf: [&quot;vault_user1&quot;, &quot;vault_password1&quot;]
      service1.env: [&quot;vault_secret1&quot;]
    service2:
      service2.conf: [&quot;vault_user2&quot;, &quot;vault_password2&quot;]
  
  - name: place secrets
    replace:
      path: &quot;/tmp/{{ repositories }}/{{ item.key }}&quot;
      regexp: &quot;{{ item.value }}&quot;
      replace: &quot;{{ item.value }}&quot;
    with_items: &quot;{{ repositories }} | dict2items&quot;
  </code></pre>
  <p>vault.yaml</p>
  <pre class="lang-yaml prettyprint-override"><code>vault_user1: a
  vault_password1: b
  vault_user2: c
  vault_password1: d
  vault_secret1: e
  </code></pre>
  <p>service1.conf</p>
  <pre><code>user=vault_user1
  password=vault_password1
  secret=vault_secret1
  </code></pre>
  <p>service2.conf</p>
  <pre><code>user=vault_user2
  password=vault_password2
  </code></pre>