Calling the inventory created by first task to the second one

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

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html

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 .