diff --git a/defaults/main.yml b/defaults/main.yml index d9040ad..e7a02ce 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,3 +4,7 @@ nginx__remove_default: true nginx__upstreams: [] nginx__sites: [] nginx__stream: '' + +nginx__geoip_country: null +nginx__geoip_city: null +nginx__geoip2: [] diff --git a/files/conf.d/geoip.conf b/files/conf.d/geoip.conf deleted file mode 100644 index b56fc80..0000000 --- a/files/conf.d/geoip.conf +++ /dev/null @@ -1 +0,0 @@ -geoip_country /usr/share/GeoIP/GeoIPv6.dat; diff --git a/tasks/install.yml b/tasks/install.yml index f62eb0a..6f883bb 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -3,8 +3,8 @@ notify: nginx | Restart Nginx apt: name: - - geoip-database - libnginx-mod-http-geoip + - libnginx-mod-http-geoip2 - nginx - name: Create directories for Nginx configuration @@ -46,7 +46,7 @@ - name: Install Nginx configs notify: nginx | Restart Nginx template: - src: 'files/conf.d/geoip.conf' + src: 'templates/conf.d/geoip.conf' dest: '{{ nginx__confd_dir }}/geoip.conf' mode: 'u=rw,go=r' owner: root diff --git a/tasks/purge.yml b/tasks/purge.yml index c42f495..e023f26 100644 --- a/tasks/purge.yml +++ b/tasks/purge.yml @@ -5,6 +5,7 @@ purge: true name: - libnginx-mod-http-geoip + - libnginx-mod-http-geoip2 - nginx - nginx-common - nginx-core diff --git a/tasks/remove.yml b/tasks/remove.yml index 2d226d5..15c148d 100644 --- a/tasks/remove.yml +++ b/tasks/remove.yml @@ -5,6 +5,7 @@ purge: false name: - libnginx-mod-http-geoip + - libnginx-mod-http-geoip2 - nginx - nginx-common - nginx-core diff --git a/templates/conf.d/geoip.conf b/templates/conf.d/geoip.conf new file mode 100644 index 0000000..620ee4f --- /dev/null +++ b/templates/conf.d/geoip.conf @@ -0,0 +1,18 @@ +{% if nginx__geoip_country %} +geoip_country {{ nginx__geoip_country }}; +{% else %} +#geoip_country path/to/GeoIP.dat; +{% endif %} +{% if nginx__geoip_city %} +geoip_city {{ nginx__geoip_city }}; +{% else %} +#geoip_city path/to/GeoLiteCity.dat; +{% endif %} +{% for geoip2 in nginx__geoip2 %} + +geoip2 {{ geoip2.file }} { +{% for map in geoip2.maps %} + ${{ map.var }} {{ map.path }}; +{% endfor %} +} +{% endfor %}