I wrote the ansible playbook to build the servers in azure. However, after the servers are built , i couldn't able to write host private IP to inventory file.
For instance, if two servers were created using ansible.Each of them will be having different private IP's. here i am trying to add the two servers into a different inventory groups. server1 should be in group A, group C, group D and Server 2 should be in group B, group F . To achieve this , i am using ansible "add_host" module.
- name: add host to inventory
add_host:
name: "{{ priavte_ip1_from_azure }}"
groups:
- group A
- group C
- group D
- name: add host to inventory
add_host:
name: "{{ priavte_ip2_from_azure }}"
groups:
- group B
- group F
Expected output:
Group A
hosts:
private-ip-1
Group B
hosts:
private-ip-2
Group C
hosts:
private-ip-1