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