diff --git a/config/ansible/tasks/servers/services/echoip/echoip.yml b/config/ansible/tasks/servers/services/echoip/echoip.yml index 71c8dab..8e094d0 100644 --- a/config/ansible/tasks/servers/services/echoip/echoip.yml +++ b/config/ansible/tasks/servers/services/echoip/echoip.yml @@ -22,12 +22,26 @@ state: directory mode: "0755" + # Download all databases - name: Download GeoLite2 ASN database ansible.builtin.get_url: url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key={{ maxmind_license_key }}&suffix=tar.gz" dest: "{{ echoip_data_dir }}/GeoLite2-ASN.tar.gz" mode: "0644" + - name: Download GeoLite2 City database + ansible.builtin.get_url: + url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={{ maxmind_license_key }}&suffix=tar.gz" + dest: "{{ echoip_data_dir }}/GeoLite2-City.tar.gz" + mode: "0644" + + - name: Download GeoLite2 Country database + ansible.builtin.get_url: + url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={{ maxmind_license_key }}&suffix=tar.gz" + dest: "{{ echoip_data_dir }}/GeoLite2-Country.tar.gz" + mode: "0644" + + # Extract all databases - name: Extract GeoLite2 ASN database ansible.builtin.unarchive: src: "{{ echoip_data_dir }}/GeoLite2-ASN.tar.gz" @@ -35,17 +49,6 @@ remote_src: true register: asn_extracted - - name: Move ASN database to correct location - ansible.builtin.command: - cmd: "mv {{ echoip_data_dir }}/GeoLite2-ASN_*/GeoLite2-ASN.mmdb {{ echoip_data_dir }}/GeoLite2-ASN.mmdb" - when: asn_extracted.changed - - - name: Download GeoLite2 City database - ansible.builtin.get_url: - url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key={{ maxmind_license_key }}&suffix=tar.gz" - dest: "{{ echoip_data_dir }}/GeoLite2-City.tar.gz" - mode: "0644" - - name: Extract GeoLite2 City database ansible.builtin.unarchive: src: "{{ echoip_data_dir }}/GeoLite2-City.tar.gz" @@ -53,17 +56,6 @@ remote_src: true register: city_extracted - - name: Move City database to correct location - ansible.builtin.command: - cmd: "mv {{ echoip_data_dir }}/GeoLite2-City_*/GeoLite2-City.mmdb {{ echoip_data_dir }}/GeoLite2-City.mmdb" - when: city_extracted.changed - - - name: Download GeoLite2 Country database - ansible.builtin.get_url: - url: "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key={{ maxmind_license_key }}&suffix=tar.gz" - dest: "{{ echoip_data_dir }}/GeoLite2-Country.tar.gz" - mode: "0644" - - name: Extract GeoLite2 Country database ansible.builtin.unarchive: src: "{{ echoip_data_dir }}/GeoLite2-Country.tar.gz" @@ -71,11 +63,51 @@ remote_src: true register: country_extracted + # Move all databases to the correct locations + - name: Move ASN database to correct location + ansible.builtin.command: + cmd: "find {{ echoip_data_dir }} -name GeoLite2-ASN.mmdb -exec mv {} {{ echoip_data_dir }}/GeoLite2-ASN.mmdb \\;" + when: asn_extracted.changed + + - name: Move City database to correct location + ansible.builtin.command: + cmd: "find {{ echoip_data_dir }} -name GeoLite2-City.mmdb -exec mv {} {{ echoip_data_dir }}/GeoLite2-City.mmdb \\;" + when: city_extracted.changed + - name: Move Country database to correct location ansible.builtin.command: - cmd: "mv {{ echoip_data_dir }}/GeoLite2-Country_*/GeoLite2-Country.mmdb {{ echoip_data_dir }}/GeoLite2-Country.mmdb" + cmd: "find {{ echoip_data_dir }} -name GeoLite2-Country.mmdb -exec mv {} {{ echoip_data_dir }}/GeoLite2-Country.mmdb \\;" when: country_extracted.changed + # Clean up unnecessary files + - name: Remove downloaded tar.gz files + ansible.builtin.file: + path: "{{ echoip_data_dir }}/GeoLite2-ASN.tar.gz" + state: absent + + - name: Remove extracted ASN folder + ansible.builtin.command: + cmd: "find {{ echoip_data_dir }} -type d -name 'GeoLite2-ASN_*' -exec rm -rf {} +" + + - name: Remove downloaded City tar.gz file + ansible.builtin.file: + path: "{{ echoip_data_dir }}/GeoLite2-City.tar.gz" + state: absent + + - name: Remove extracted City folder + ansible.builtin.command: + cmd: "find {{ echoip_data_dir }} -type d -name 'GeoLite2-City_*' -exec rm -rf {} +" + + - name: Remove downloaded Country tar.gz file + ansible.builtin.file: + path: "{{ echoip_data_dir }}/GeoLite2-Country.tar.gz" + state: absent + + - name: Remove extracted Country folder + ansible.builtin.command: + cmd: "find {{ echoip_data_dir }} -type d -name 'GeoLite2-Country_*' -exec rm -rf {} +" + + # Deploy and restart the EchoIP service - name: Deploy EchoIP docker-compose.yml ansible.builtin.template: src: docker-compose.yml.j2