title: Pass variable in Ansible inventory and call with ansible playbook command
body: <p>I have an inventory file which contains this information:</p>
  <pre><code>Test-server ansible_host=10.0.0.8 ansible_user=root
  </code></pre>
  <p>ansible playbook to create a file in tmp directory:</p>
  <pre><code>- hosts: '{{ is_host }}'
    tasks:
      - name: Creating yml file in tmp directory
        file:
          path: &quot;/tmp/ansible-playbook.yml&quot;
          state: touch
  </code></pre>
  <p>I can execute this playbook with the command:</p>
  <pre><code>ansible-playbook -i inventory tmp-file.yml --extra-vars &quot;is_host=xyz-server&quot;
  </code></pre>
  <p>I want this <code>Test-server</code> to be set as variable in inventory (INI) file, something like this:</p>
  <pre><code>{{is_host}} ansible_host=10.0.0.8 ansible_user=root
  </code></pre>
  <p>...and pass the value in ansible-playbook command.</p>
  <p>Actually, I am using Azure devops to grab the server's host name dynamically from pipeline task and want to assign the value in Ansible inventory. When I use Host list in Ansible task it grabs the value and assign to host as below:
  <a href="https://i.stack.imgur.com/SRB2V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SRB2V.png" alt="host-list-ansible-task" /></a></p>
  <p>...but when I select <code>Inventory Location</code> as File then it does not pick host value from previous.
  <a href="https://i.stack.imgur.com/DTdlZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTdlZ.png" alt="file-as-inventory-location" /></a></p>
  <p>... that's why I am looking a way to pass <code>hostname</code> as variable in inventory file which I can use anywhere.</p>