Passing IP address from one playbook to another playbook

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

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.

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

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

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