# How to find the current VM where play is running

**URL:** <https://forum.ansible.com/t/how-to-find-the-current-vm-where-play-is-running/35426>\
**Category:** Ansible Project\
**Created:** [June 28, 2021, 2:52pm UTC](https://forum.ansible.com/t/how-to-find-the-current-vm-where-play-is-running/35426 "2021-06-28T14:52:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajaniesh\_Kaushikk](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@Rajaniesh\_Kaushikk](https://forum.ansible.com/u/Rajaniesh_Kaushikk)\
**Post date:** [June 28, 2021, 2:52pm UTC](https://forum.ansible.com/t/how-to-find-the-current-vm-where-play-is-running/35426/1 "2021-06-28T14:52:56Z")

</div>

Hi,  
I want to automate the software deployment via ansible.Here is my problem where I need some help:

When I run the playbook it goes through inventory to install software on a remote VM and update software config file on each VM. In the software config file I need to add the currently executing VM’s IP address. For example If I have inventory like this

airflowvm ansible\_host=55.255.153.166 ansible\_connection=ssh ansible\_user=user1 ansible\_ssh\_pass=my secret password  
azurevm ansible\_host=58.255.153.166 ansible\_connection=ssh ansible\_user=user2 ansible\_ssh\_pass=my secret password

so when my playbook runs on airflowvm it will will update the softwareconfig.config file the entry like this http://[55.255.153.166:8080/salesApp](http://55.255.153.166:8080/salesApp)  
but when it runs on azurevm it will will update the softwareconfig.config file the entry like this http://[58.255.153.166:8080/salesApp](http://58.255.153.166:8080/salesApp)

For this I need to extract the currently executing VM by the playbook and use the ansible\_host from it but I am not sure how to do it? Currently I am using this but it may not work if more then 1 vm is here in the inventory file.

- name: set Facts  
set\_fact:  
address: “{{hostvars[inventory\_hostname][‘ansible\_host’]}}”

- debug: msg=“{{address }}”

Any pointers would be appreciated?  
Regards  
Rajanish
