Ansible: Nginx w/ GeoIP2


I’ve been struggling on how to load balance using user location. Yes, you can easily do this using AWS Route 53 or another cloud load balancer. But this way is expensive. Nginx Plus can do it out of the box, but the Open Source version cannot.

Hank Cheah has an amazing tutorial on how to compile Nginx with GeoIp2 from MaxMind! It works great and is simple to follow. Took me about an hour to get it up and running by hand.

But I think I can improve it slightly, with Ansible! Here’s my playbook:

Shell

Don’t forget to change the variables at the top. This will do all the steps for you in about 5 minutes and you’ll be up and running.