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
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
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