title: Ansible Jinja template - read file line by line
body: <p>I am trying to parse a text file line by line inside of a for loop. I can parse JSON data fine, but a seemingly simpler task is failing here. It appears Jinja is not delineating based on line-feeds.</p>
  
  <p>In my YAML playbook I have declared the source file and lookup (query) function:</p>
  
  <pre><code>vars:
      myfile: /some/text/file.txt
      myfile_list: "{{ query('file', myfile) }}"
  </code></pre>
  
  <p>The source file 'myfile' is simply a list of IPs in CIDR format:</p>
  
  <pre><code>1.2.3.4/32
  5.6.7.8/32
  10.20.30.0/24
  </code></pre>
  
  <p>In the Jinja2 template file I am running a for loop:</p>
  
  <pre><code>{% for line in myfile_list %}
  permit ip {{ line }} any
  {% endfor %}
  </code></pre>
  
  <p>The desired output is:</p>
  
  <pre><code>permit ip 1.2.3.4/32 any
  permit ip 5.6.7.8/32 any
  permit ip 10.20.30.0/24 any
  </code></pre>
  
  <p>Instead I get this:</p>
  
  <pre><code>permit ip 1.2.3.4/32
  5.6.7.8/32
  10.20.30.0/24 any
  </code></pre>
  
  <p>I have tried the lookup plugin instead. Setting 'wantlist=True'. Following the lookup call using the list filter. I either get one character per line, or a single blob of text as shown above. If I run the Linux shell command 'file' against my source file it's seen as "ASCII text".</p>