# Passing IP address from one playbook to another playbook

**URL:** <https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [June 5, 2021, 3:55am UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288 "2021-06-05T03:55:42Z")\
**Posts on this page:** 5\
**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 5, 2021, 3:55am UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288/1 "2021-06-05T03:55:42Z")

</div>

I have developed the playbook which created a vm in azure(playbook name is CreateAzureVM.yml) and I have another playbooks which Installs softwares on the VM(install\_software.yml).

I have imported install\_software.yml in the CreateAzureVM.yml playbook. install\_software.yml takes the host info from inventory file which contains ansible\_connection=ssh ansible\_ssh\_pass=XYZ ansible\_host=IPaddressOfTheHost

Now my requirement is that I want to pass the IP address of the newly created machine to the Imported playbook so instead of taking the static IP provided in the inventory it can take it dynamically from the CreateAzureVM.yml.

I already tried to update the inventory file but looks like updating the inventory file in the middle of CreateAzureVM playbook does not help because inventory file is already loaded and updating it afterward does not help.

Any quick help would be greatly appreciated.

Regards

Rajaniesh

---

<div class="post-metadata">

**Author:** ![Gaurav\_Gupta](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@Gaurav\_Gupta](https://forum.ansible.com/u/Gaurav_Gupta)\
**Post date:** [June 5, 2021, 4:04am UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288/2 "2021-06-05T04:04:08Z")

</div>

According to your need, what i understand. It may be work for you.

**- name: Refresh Inventory File**  
**meta: refresh\_inventory**  
**- pause:**  
**minutes: 1**

Add these line in last of CreateAzurevm playbook.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 5, 2021, 5:58am UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288/3 "2021-06-05T05:58:38Z")

</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:** ![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 5, 2021, 10:36am UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288/4 "2021-06-05T10:36:12Z")

</div>

I tried doing it but it did not worked because imported playbook still taking the ip address from inventory file.

---

<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 7, 2021, 3:56pm UTC](https://forum.ansible.com/t/passing-ip-address-from-one-playbook-to-another-playbook/35288/5 "2021-06-07T15:56:45Z")

</div>

Let me post the playbook to help you understand it better

I have two playbooks  
1: Install azure vm  
2 install mongo db and tomcat  
I want to integrate both so first one send ip to second playbook and second play book does its job/

First playbook code is here:  
AzurePlaybook.yml

-----All the other tasks----

azure\_rm\_publicipaddress:  
resource\_group: Solutioning  
allocation\_method: Static  
name: PublicIP  
register: output\_ip\_address

- name: Include another playbook  
import\_playbook: install\_MongoDb\_and\_Tomcat.yml

In Install MongoDB and Tomcat Playbook here is the code

install\_MongoDb\_and\_Tomcat.yml
