Passing IP address from one playbook to another playbook

51 views
Skip to first unread message

Rajaniesh Kaushikk

unread,
Jun 4, 2021, 11:55:42 PM6/4/21
to Ansible Project

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

Gaurav Gupta

unread,
Jun 5, 2021, 12:04:08 AM6/5/21
to Ansible Project
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.

Dick Visser

unread,
Jun 5, 2021, 1:59:03 AM6/5/21
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b258177c-e912-4c61-9df0-1bf7c06bdad7n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Rajaniesh Kaushikk

unread,
Jun 5, 2021, 6:36:37 AM6/5/21
to ansible...@googlegroups.com
I tried doing it but it did not worked because imported playbook still taking the ip address from inventory file.

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/9EUeAeApdUc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwNfSEcC473SaxKrr1VgCCFaHoy-bRhBh%3DLpJCtZNjmQHg%40mail.gmail.com.

Rajaniesh Kaushikk

unread,
Jun 7, 2021, 11:56:45 AM6/7/21
to Ansible Project
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

---
- name: install Mongo and Tomcat
  hosts:  demo1
  become: yes
  become_method: sudo       # Set become method
  remote_user: azureuser         # Update username for remote server
  
  vars:
    tomcat_ver: 9.0.30                          # Tomcat version to install
    ui_manager_user: manager                    # User who can access the UI manager section only
    ui_manager_pass: Str0ngManagerP@ssw3rd      # UI manager user password
    ui_admin_username: admin                    # User who can access bpth manager and admin UI sections
    ui_admin_pass: Str0ngAdminP@ssw3rd
    # UI admin password
  roles:
    - install_mongodb
    - mongo_post_install
    - install_tomcat
    - tomcat_post_install


I have used  import playbook and I want to pass the IP address instead of taking it from inventory file currently install_MongoDb_and_Tomcat.yml playboook taking it from hosts: demo1 which is declared in the inventory file
Reply all
Reply to author
Forward
0 new messages