# Determine if on internal LAN

**URL:** <https://forum.ansible.com/t/determine-if-on-internal-lan/16518>\
**Category:** Ansible Project\
**Created:** [October 15, 2014, 3:07pm UTC](https://forum.ansible.com/t/determine-if-on-internal-lan/16518 "2014-10-15T15:07:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [October 15, 2014, 3:07pm UTC](https://forum.ansible.com/t/determine-if-on-internal-lan/16518/1 "2014-10-15T15:07:09Z")

</div>

I perform a couple steps during server provisioning in-house prior to sending out to a data center. We have most installers/packages available on some internal http servers to speed up retrieving them, I would like to keep the same playbook but change the url to retrieve installers from during the run based on current network.

Any one have any clever ways to alter the url in a “get\_url” command to choose the local network if on local network else use an external internet address?

i.e.  
if ansible\_ssh\_host is in 192.168.0.0/16 do foo else do bar.

---

<div class="post-metadata">

**Author:** ![James\_Martin1](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@James\_Martin1](https://forum.ansible.com/u/James_Martin1)\
**Post date:** [October 15, 2014, 3:54pm UTC](https://forum.ansible.com/t/determine-if-on-internal-lan/16518/2 "2014-10-15T15:54:36Z")

</div>

Rishi,

Let’s assume you have an inventory group called “datacenter” that holds all of your datacenter machines and an inventory group named “inhouse” that holds all of your in-house machines.

You would then have a group\_var file called “inventory/group\_var/inhouse” that would contain:

`url: http://my.internal.company.com`

And also have a a group\_var file called “inventory/group\_var/datacenter” that would contain:

`  
url: [http://my.datacenter.company.com](http://my.datacenter.company.com)

`

your tasks would look something like:

`

- name: get tmy file  
get\_url: {{ url }}/foo.pkg dest=/tmp/foo.pkg

`

When your run your playbook in-house, it’s going to use the internal url based on the machine’s membership to the inhouse group. When the physical machines have moved from in-house to datacenter, also change their inventory group membership. The playbook will now use the datacenter url based on the machine’s membership to the datacenter group.

- James

---

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [October 15, 2014, 8:17pm UTC](https://forum.ansible.com/t/determine-if-on-internal-lan/16518/3 "2014-10-15T20:17:23Z")

</div>

Good idea, thanks.
