title: Grep vars from a file with ansible to use later in a task with a for loop
body: <p>I am relatively new to ansible. </p>
  
  <p>I have a <code>parameters.yml</code> with something like this: </p>
  
  <pre><code>parameters: 
    stuff: bullshit
    otherstuff: otherbullshit
    domain_locale: domain.locale.test
    domain_differentlocale1: domain.differentlocale1.test
    domain_differentlocale2: domain.differentlocale2.test
    domain_differentlocale3: domain.differentlocale3.test
    uninteresting_stuff: uninteresting_bullshit
  </code></pre>
  
  <p>This file is in another directory, but I could also symlink it to be in defaults/main.yml. Doesn't matter. </p>
  
  <p>What I would like to accomplish is grep somehow within an ansible task these <code>domain.*.test</code> values and use it as vars in another task with ansible. This other task would be to write it directly after <code>127.0.0.1 localhost</code> in the same line in the <code>/etc/hosts</code>. </p>
  
  <p>I am not even sure which of the modules to use in ansible. <code>include_vars</code> has no additional grep as I see it. <code>set_fact</code> does not read from a different file(can I combine it with a shell command? how?). <code>lineinfile</code> does not have a source and dest, so it is also limited to one file. </p>
  
  <p>I also thought this post would help me: <a href="https://stackoverflow.com/questions/43656563/ansible-read-multiple-variables-with-same-name-from-vars-file">Ansible read multiple variables with same name from vars_file</a>
  but it does not need the grep part, I need.</p>