title: ansible read parameter value from file
body: <p>I have a file that looks similarly:</p>
  <pre><code># some comment
  foo/variable1 = value1
  bar/variable2 = value2
  </code></pre>
  <p>etc..</p>
  <p>I have been trying to come up with an ansible logic to look up one particular variable of interest from this file.
  For example if I need to get value2 assigned to myvar in ansible.</p>
  <p>tried lineinfile first something like this:</p>
  <pre><code>- name: taskname
    lineinfile:
      path: /path/to/file
      regexp: '^bar/variable2.*$'
      line: dummy
    register: myvar
    check_mode: yes
  </code></pre>
  <p>didn't work. I also tried to escape the / character in the regexp pattern but that wasn't the problem. Then I tried lookup ini file something like:</p>
  <pre><code>vars: 
    myvar: &quot;{{ lookup('ini', 'bar/variable2 file=/path/to/file') }}&quot;
  </code></pre>
  <p>but the file doesn't have sections so this fails too.</p>
  <p>I tried using regex_search too in different ways but I just can't seem to have it working. I'd appreciate if somebody can help me. I wish lookup ini file would have a version where the section is optional. There are some parameter files that follow very similar format except they don't have sections in them.</p>