# Getting the local IP

**URL:** <https://forum.ansible.com/t/getting-the-local-ip/12956>\
**Category:** Ansible Project\
**Created:** [June 13, 2013, 5:03pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956 "2013-06-13T17:03:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias\_Bogaert](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mathias\_Bogaert](https://forum.ansible.com/u/Mathias_Bogaert)\
**Post date:** [June 13, 2013, 5:03pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/1 "2013-06-13T17:03:16Z")

</div>

Hi,

How do I insert my public facing IP (from the machine running Ansible aka client)? Usecase: insert my own IP in sshguard’s whitelist.

Thanks!

Mathias

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [June 13, 2013, 5:11pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/2 "2013-06-13T17:11:32Z")

</div>

> How do I insert my public facing IP (from the machine running Ansible aka  
> client)? Usecase: insert my own IP in sshguard's whitelist.

Use one of the myriad 'what's my IP address' services (e.g.  
[http://ifconfig.me](http://ifconfig.me)), register the output in a variable and use that  
further in the play.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [June 13, 2013, 5:19pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/3 "2013-06-13T17:19:04Z")

</div>

> \> How do I insert my public facing IP (from the machine running Ansible aka  
> \> client)? Usecase: insert my own IP in sshguard's whitelist.
> 
> Use one of the myriad 'what's my IP address' services (e.g.  
> [http://ifconfig.me](http://ifconfig.me)), register the output in a variable and use that  
> further in the play.

My personal favorite is icanhazip.com, it just returns the IP as plain text.

For details, see [https://major.io/icanhazip-com-faq/](https://major.io/icanhazip-com-faq/)

Lorin

---

<div class="post-metadata">

**Author:** ![Lester\_Wade](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Lester\_Wade](https://forum.ansible.com/u/Lester_Wade)\
**Post date:** [June 13, 2013, 5:19pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/4 "2013-06-13T17:19:36Z")

</div>

Hey Mathias,

Are you running “In The Cloud” (I couldn’t find a hipster font for this)? Or is this IP natted or something? A system fact doesn’t satisfy?

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [June 13, 2013, 6:25pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/5 "2013-06-13T18:25:12Z")

</div>

> My personal favorite is icanhazip.com, it just returns the IP as plain text.

JSON anybody? [http://jsonip.appspot.com](http://jsonip.appspot.com)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;-)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [June 13, 2013, 6:45pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/6 "2013-06-13T18:45:24Z")

</div>

​ansible localhost -m uri -a url=[http://ifconfig.me/all.json](http://ifconfig.me/all.json)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 13, 2013, 7:22pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/7 "2013-06-13T19:22:12Z")

</div>

BTW, the register keyword is the great way to save the CLI result of command in a variable.

Not sure how much that service likes you pounding on it in automated fashion 🙂

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [June 13, 2013, 8:37pm UTC](https://forum.ansible.com/t/getting-the-local-ip/12956/8 "2013-06-13T20:37:03Z")

</div>

> Not sure how much that service likes you pounding on it in automated  
> fashion 🙂

Very true.

One (little-known) service that explicitly allows that is OpenDNS, who  
provide a DNS server that returns an A record containing the IP address  
of the requestor. In the context of the original poster, that would be  
my "outside" IP address:

ansible localhost -m command -a 'dig +short myip.opendns.com @resolver1.opendns.com'

Needless to say, this means that the host running this needs to be able  
to resolve and access that DNS service.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP
