Determine if on internal LAN

18 views
Skip to first unread message

Rishi

unread,
Oct 15, 2014, 11:07:09 AM10/15/14
to ansible...@googlegroups.com
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.

James Martin

unread,
Oct 15, 2014, 11:54:36 AM10/15/14
to ansible...@googlegroups.com
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:



And also  have a a group_var file called  "inventory/group_var/datacenter" that would contain:

url: 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

Rishi

unread,
Oct 15, 2014, 4:17:23 PM10/15/14
to ansible...@googlegroups.com
Good idea, thanks.
Reply all
Reply to author
Forward
0 new messages