title: Lookup inside lookup - ansible
body: <p>I am trying to use the lookup plugin to lookup the environment variable from inside a lookup function that looks up a file.</p>
  
  <p>So the file name is _hosts.txt and i want the lookup function to replace the ENV with the passed environment variable.</p>
  
  <p>I looked up at the ansible documentation for lookup and still couldnt figure out the error.</p>
  
  <p>Here is the code block:</p>
  
  <pre><code>- name: "Update the /etc/hosts file"
    blockinfile:
     block: "{{ lookup('file', ' + lookup('env', 'ENV') +_hosts.txt') }}"
     dest: "/etc/hosts"
     backup: yes
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>FAILED! => {"msg": "template error while templating string: expected
    token ',', got 'env'. String: {{ lookup('file', ' + lookup('env',
    'ENV') +_hosts.txt') }}"}</p>
  </blockquote>
  
  <p>I know its a syntax issue but just cant figure out what it is.</p>