0

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
learning fun
  • 519
  • 1
  • 5
  • 12
  • As per official docs for [add-host](https://docs.ansible.com/ansible/latest/modules/add_host_module.html), this add a host (and alternatively a group) to the ansible-playbook in-memory inventory. As per i understand by your question, you want to add host in inventory.ini file. – Krishnom Apr 02 '19 at 02:45
  • Thank you for the reply. Yes, i am trying to add the hosts to inventory.ini file. – learning fun Apr 02 '19 at 15:57
  • I guess your question is answered here then https://github.com/ansible/ansible/issues/45384 . Hope this helps. – Krishnom Apr 03 '19 at 02:43
  • Thank you but i couldn't able to get the private ip address of remote host. – learning fun Apr 03 '19 at 17:32

0 Answers0