title: How I can use Variables in Ansible json_query?
body: <p>I want to use a ansible variable inside the json query filter.
  This is my Code:</p>
  <p>Playbook execution:</p>
  <pre><code>ansible-playbook debug.yml -e &quot;project_environment=live&quot;
  </code></pre>
  <pre class="lang-yaml prettyprint-override"><code>- debug:
      msg: &quot;{{ project_environment }}&quot;
  
  - debug:
      msg: &quot;{{ check_objects | json_query('`{{project_environment}}`.current') }}&quot;
  </code></pre>
  <p>This is my dictionary:</p>
  <pre class="lang-yaml prettyprint-override"><code>check_objects:
    live:
      current:
      - example.com
      next:
      - next.example.com
  </code></pre>
  <p>This is what i got:</p>
  <pre><code>TASK [debug : debug] 
  ok: [sample-hostname] =&gt; {
      &quot;msg&quot;: &quot;live&quot;
  }
  
  TASK [debug  : debug]
  ok: [sample-hostname] =&gt; {
      &quot;msg&quot;: &quot;&quot;
  }
  </code></pre>
  <p><strong>When i replace the variable by using the expected value, the output it is working fine:</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>- debug:
      msg: &quot;{{ check_objects | json_query('live.current') }}&quot;
  </code></pre>
  <pre><code>TASK [typo3-deployment/check : debug] 
  ok: [sample-hostname] =&gt; {
      &quot;msg&quot;: [
          &quot;example.com&quot;
      ]
  }
  </code></pre>
  <p>I think it runs in trouble while interpolate the variable.</p>
  <p>I have tried this solution but it doesn't work too: <a href="https://stackoverflow.com/questions/46038985/ansible-pass-a-variable-in-a-json-query-filter">Ansible : pass a variable in a json_query filter</a></p>