title: Ansible use encrypted variables in other variables
body: <p>I'm building several playbooks that can perform various maintenance tasks. For this they need MySQL login accounts. There are several db servers so I've created a variable that holds all the info. Example to illustrate things:</p>
  
  <pre><code>./vars/main.yml
  
    # 'secret' variables
    host1url: some_url
    host1user: user
    host1pass: pass
    host2url: some_url
    host2user: user
    host2pass: pass
  
  
    # array of db hosting info
    dbhosts:
      - name: host1
        host: {{ host1url }}
        user: {{ host1user }}
        pass: {{ host1pass }}
      - name: host2
        host: {{ host2url }}
        user: {{ host2user }}
        pass: {{ host2pass }}
  
  ./roles/the_role/tasks/main.yml
      - name: create script to perform task
        template:
          src=do_something.sh
          dest=do_something_{{ item.name }}.sh
        with_items:
          dbhosts
  
      - name: perform task
        command: do_something_{{ item.name }}.sh
        with_items:
          dbhosts
  </code></pre>
  
  <p>This works, but I'd like to move the 'secret' variables to a different file so I can:</p>
  
  <ul>
  <li>add in a different set of users based on a specific playbook or situation</li>
  <li>make the file encrypted for use with Ansible Vault</li>
  </ul>
  
  <p>How can I leave the dbhosts structure in the main.yml file for reference AND move the 'secret' variables to a different file?</p>
  
  <p>All I can find is info on how to add a file with variables in a task during runtime, but shouldn't it be loaded before the variable 'dbhosts' is loaded so the expansion of the variables in the dbhosts is going to work?</p>