- name: Check if mod already installed
  stat:
    path: "{{ minetest_game_dir }}/mods/{{ item.name }}"
  register: minetest_mod

- name: Download one minetest mod
  get_url:
    url: "{{item.url}}"
    dest: "{{ downloads_dir }}/{{ item.name }}.zip"
    mode: 0440
  when: not minetest_mod.stat.exists

- name: Extract mod into mods of current game
  unarchive:
    src: "{{ downloads_dir }}/{{ item.name }}.zip"
    dest: "{{ minetest_game_dir }}/mods"
  when: not minetest_mod.stat.exists

- name: Check if mod name has 'master' in it
  stat:
    path: "{{ minetest_game_dir }}/mods/{{ item.name }}-master"
  register: minetest_mod_master

- name: Rename mod to canonical name if has '-master' in name
  command: mv "{{ minetest_game_dir }}/mods/{{ item.name }}-master" "{{ minetest_game_dir }}/mods/{{ item.name }}"
  when: minetest_mod_master.stat.exists
