Can Ipaddress of the target be fetched by ansible?

120 views
Skip to first unread message

anirudh vasudevan

unread,
Nov 11, 2016, 12:55:27 PM11/11/16
to Ansible Project


I know the conventional way of using Ansible is copying the ssh key on to the target and then adding the ip address to the inventory file. In my case I will not know the Ip address of the target that am testing on, how can ansible get me the ip address? Any workaround

Thanks in advance

Thanks,

Anirudh Vasudevan

Kai Stian Olstad

unread,
Nov 11, 2016, 4:20:41 PM11/11/16
to ansible...@googlegroups.com
On 11. nov. 2016 18:30, anirudh vasudevan wrote:
> I know the conventional way of using Ansible is copying the ssh key on to
> the target and then adding the ip address to the inventory file.

I don't agree in this statement, I use hostname and username/password.

> In my case
> I will not know the Ip address of the target that am testing on, how can
> ansible get me the ip address? Any workaround

DNS?

--
Kai Stian Olstad

anirudh vasudevan

unread,
Nov 11, 2016, 5:52:48 PM11/11/16
to Ansible Project, ansible-pr...@olstad.com
Thanks for the reply.

No what I meant was how can you make ansible talk to a target host without ansible host file not hard coding with the ip address, am newbie to ansible. Apologizes if this seems straightforward.

Thanks,
Anirudh Vasudevan

Kai Stian Olstad

unread,
Nov 11, 2016, 6:05:09 PM11/11/16
to ansible...@googlegroups.com
On 11. nov. 2016 23:52, anirudh vasudevan wrote:
> No what I meant was how can you make ansible talk to a target host without
> ansible host file not hard coding with the ip address, am newbie to
> ansible. Apologizes if this seems straightforward.

Yes, that was what i tried to say.
You don't have to use the IP in the inventory file, you can use the
hostname, Ansible do use DNS to do lookup.

If that do not answer your question you need to provide us with a lot
more information about you setup.

--
Kai Stian Olstad

Dick Davies

unread,
Nov 12, 2016, 6:16:04 AM11/12/16
to ansible list
It's hard to give details because you haven't explained why you don't
know the IP.

I've used multicast DNS (via avahi ) on DHCP booted Raspberry Pis to
advertise hostnames, then
put those hostnames into groups in flat file inventories.

That means the servers can change IP without having to update any
config on the ansible node.

You're copying this key up so you'll need some way to find the server, right?
Ansible inventories can be scripts as well as flat files (that's how
things like it's cloud support
works). There's lots of information at:

http://docs.ansible.com/ansible/intro_dynamic_inventory.html
> --
> 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 post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9e626ca7-888e-4f4a-9224-6bc580506a4b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages