# Calling the inventory created by  first task to the second one

**URL:** <https://forum.ansible.com/t/calling-the-inventory-created-by-first-task-to-the-second-one/38103>\
**Category:** Ansible Project\
**Created:** [June 14, 2023, 12:33pm UTC](https://forum.ansible.com/t/calling-the-inventory-created-by-first-task-to-the-second-one/38103 "2023-06-14T12:33:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [June 14, 2023, 12:33pm UTC](https://forum.ansible.com/t/calling-the-inventory-created-by-first-task-to-the-second-one/38103/1 "2023-06-14T12:33:03Z")

</div>

Hi,

I have a playbook book with 2 tasks in it .  
In the first tasks, I have playbooks to create a VM and build OS on it and able to login to the VM manually (for testing) , and the final play creates a temporary inventory file like below.

[dev-vm1]

mytestvm1 ansible\_ssh\_private\_key\_file: mykey.pem ansible\_ssh\_user: “root” ansible\_ssh\_extra\_args: ‘-o StrictHostKeyChecking=no’

the second tasks has a bunch of plays which needs to login to the mytestvm1(using the temp inventory file)above and execute .

I have a main.yml like this

- name: main.play  
hosts: localhost  
tasks:  
play1:  
play2:  
play3

- hosts: dev-vm1  
become: true  
gather\_facts: true  
tasks:  
play1:  
play2:  
play2

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 14, 2023, 12:47pm UTC](https://forum.ansible.com/t/calling-the-inventory-created-by-first-task-to-the-second-one/38103/2 "2023-06-14T12:47:51Z")

</div>

[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add\_host\_module.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html)

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [June 14, 2023, 3:56pm UTC](https://forum.ansible.com/t/calling-the-inventory-created-by-first-task-to-the-second-one/38103/3 "2023-06-14T15:56:54Z")

</div>

Thanks a lot . I am able to overcome it .  
I was missing the indent after the add\_host earlier for the second task and now I can .
