Add existing code

This commit is contained in:
Alex Kotov 2023-11-08 19:36:02 +04:00
commit 3d593df9d0
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
11 changed files with 119 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Alex Kotov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2
defaults/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
geoip__state: null

3
handlers/main.yml Normal file
View File

@ -0,0 +1,3 @@
---
- name: Update
command: 'geoipupdate'

20
meta/main.yml Normal file
View File

@ -0,0 +1,20 @@
---
allow_duplicates: false
dependencies: []
galaxy_info:
role_name: geoip
author: Alex Kotov
description: GeoIP
license: MIT
min_ansible_version: 2.8
galaxy_tags:
- geoip
- geoipupdate
- maxmind
platforms:
- name: Debian
versions:
- bookworm # Debian 12 Bookworm

22
tasks/install.yml Normal file
View File

@ -0,0 +1,22 @@
---
- name: Install system packages
notify: Update
apt:
name: '{{ geoip__packages | list }}'
- name: Create /etc/GeoIP.conf
notify: Update
template:
src: 'templates/GeoIP.conf'
dest: '/etc/GeoIP.conf'
mode: 'u=rw,go=r'
owner: root
group: root
- name: Create /etc/cron.d/geoip
copy:
content: "0 12 * * 3 root geoipupdate\n"
dest: '/etc/cron.d/geoip'
mode: 'u=rw,go=r'
owner: root
group: root

13
tasks/main.yml Normal file
View File

@ -0,0 +1,13 @@
---
- fail:
msg: 'Invalid `geoip__state`: {{ geoip__state }}'
when: (geoip__state != None) and
(geoip__state != 'purge') and
(geoip__state != 'remove') and
(geoip__state != 'install')
- include_tasks: purge.yml
when: geoip__state == 'purge'
- include_tasks: remove.yml
when: geoip__state == 'remove'
- include_tasks: install.yml
when: geoip__state == 'install'

16
tasks/purge.yml Normal file
View File

@ -0,0 +1,16 @@
---
- name: Uninstall system packages
apt:
state: absent
purge: true
name: '{{ geoip__packages | list }}'
- name: Delete /etc/cron.d/geoip
file:
state: absent
path: '/etc/cron.d/geoip'
- name: Delete /etc/GeoIP.conf
file:
state: absent
path: '/etc/GeoIP.conf'

11
tasks/remove.yml Normal file
View File

@ -0,0 +1,11 @@
---
- name: Uninstall system packages
apt:
state: absent
purge: false
name: '{{ geoip__packages | list }}'
- name: Delete /etc/cron.d/geoip
file:
state: absent
path: '/etc/cron.d/geoip'

4
templates/GeoIP.conf Normal file
View File

@ -0,0 +1,4 @@
AccountID {{ geoip__maxmind_account_id }}
LicenseKey {{ geoip__maxmind_license_key }}
EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country

6
vars/main.yml Normal file
View File

@ -0,0 +1,6 @@
---
geoip__packages:
- 'geoip-bin'
- 'geoip-database'
- 'geoipupdate'
- 'mmdb-bin'