Generalizing GeoIP to be consumed by more services
This commit is contained in:
30
roles/GeoIP/README.md
Normal file
30
roles/GeoIP/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
Geolocation by IP is a methodology
|
||||
|
||||
# Etymology
|
||||
|
||||
GeoIP is a shortening of geolocation by IP.
|
||||
|
||||
# Relevant Files and Software
|
||||
|
||||
This content is derived & packed by Arch, pulling regularly from [MaxMind](https://maxmind.com).
|
||||
|
||||
# Available Clients
|
||||
|
||||
The Python `geoip2` library can be used with snippets like below:
|
||||
|
||||
```
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import geoip2.database
|
||||
import sys
|
||||
|
||||
with geoip2.database.Reader('/etc/nginx/conf/maxmind-geoip2.mmdb') as reader:
|
||||
response = reader.country(sys.argv[1])
|
||||
print(response.country.iso_code)
|
||||
```
|
||||
|
||||
We also install the `geoiplookup` client from the GeoIP client.
|
||||
|
||||
# Equivalents or Competition
|
||||
|
||||
Whois and other tools can also provide corroboration or alternate responses for these queries.
|
||||
22
roles/GeoIP/tasks/main.yml
Normal file
22
roles/GeoIP/tasks/main.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
|
||||
- name: Install components
|
||||
become: yes
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- geoip
|
||||
- geoip-database
|
||||
- geoip-database-extra
|
||||
- libmaxminddb
|
||||
|
||||
# This is a hack while geoip-database only provides the legacy version.
|
||||
- name: Ensure GeoIP2 database is present
|
||||
become: yes
|
||||
file:
|
||||
path: /usr/share/GeoIP/GeoIP2.mmdb
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
state: file
|
||||
Reference in New Issue
Block a user