---
- name: Set SSH port
  set_fact:
    ansible_port: "{{SSH_PORT}}"

- name: Creates directory
  file:
    path: "{{nginx_dir}}/geoip"
    state: directory

- name: Creates directory
  file:
    path: "{{nginx_dir}}/scripts"
    state: directory

- name: Install wget
  package:
    name: "{{ item }}"
    state: present
  environment:
    http_proxy: "{{PROXY}}"
    https_proxy: "{{PROXY}}"
  with_items:
    - git
    - python3

- name: Copy GeoIP script in place.
  template:
    src: geoip.sh.j2
    dest: "{{nginx_dir}}/scripts/geoip.sh"
    mode: 0777

- name: Execute the script
  command: "{{nginx_dir}}/scripts/geoip.sh"

- name: Update geoip every Wednesday
  cron:
    name: "Update geoip"
    minute: "0"
    hour: "01"
    weekday: "3"
    job: "{{nginx_dir}}/scripts/geoip.sh"
  when: UPDATE == "1"
