---
- hosts: all
  roles:
    - role: kif_minetest_mapserver
      vars:
        mods_version: testing
        server_player_backend: sqlite3
        server_backend: sqlite3
        server_announce: false
        load_mods:
          - 3d_armor
          - 3d_armor_ip
          - 3d_armor_sfinv
          - 3d_armor_stand
          - 3d_armor_ui
          - advtrains
          - advtrains_assets
          - advtrains_freight_train
          - advtrains_interlocking
          - advtrains_line_automation_sync
          - advtrains_luaautomation
          - advtrains_railbus
          - advtrains_signals_ks
          - advtrains_train_industrial
          - advtrains_train_japan
          - advtrains_train_jre231
          - advtrains_train_rocket
          - advtrains_train_steam
          - advtrains_train_subway
          - advtrains_train_track
          - ak_announcer
          - ambience
          - areas
          - assets
          - bakedclay
          - basic_materials
          - basic_signs
          - beacons
          - bike
          - biome_lib
          - boards
          - bonemeal
          - building_blocks
          - character_creator
          - coloredwood
          - computer
          - computers
          - death_markers
          - digilines
          - digiterms
          - display_api
          - elevators
          - fake_fire
          - farming
          - font_api
          - font_metro
          - food
          - food_basic
          - hbarmor
          - hbhunger
          - home_workshop_common
          - home_workshop_machines
          - home_workshop_misc
          - homedecor_3d_extras
          - homedecor_bathroom
          - homedecor_bedroom
          - homedecor_books
          - homedecor_climate_control
          - homedecor_clocks
          - homedecor_cobweb
          - homedecor_common
          - homedecor_doors_and_gates
          - homedecor_electrical
          - homedecor_electronics
          - homedecor_exterior
          - homedecor_fences
          - homedecor_foyer
          - homedecor_furniture
          - homedecor_furniture_medieval
          - homedecor_gastronomy
          - homedecor_kitchen
          - homedecor_laundry
          - homedecor_lighting
          - homedecor_misc
          - homedecor_office
          - homedecor_pictures_and_paintings
          - homedecor_roofing
          - homedecor_seating
          - homedecor_tables
          - homedecor_trash_cans
          - homedecor_wardrobe
          - homedecor_windows_and_treatments
          - hudbars
          - ilights
          - illumination
          - inbox
          - itemframes
          - kif_custom
          - kiffood
          - lavalamp
          - led_marquee
          - mapserver
          - mesecar
          - mesecons
          - mesecons_alias
          - mesecons_blinkyplant
          - mesecons_button
          - mesecons_commandblock
          - mesecons_delayer
          - mesecons_detector
          - mesecons_doors
          - mesecons_extrawires
          - mesecons_fpga
          - mesecons_gates
          - mesecons_hydroturbine
          - mesecons_insulated
          - mesecons_lamp
          - mesecons_lightstone
          - mesecons_luacontroller
          - mesecons_materials
          - mesecons_microcontroller
          - mesecons_movestones
          - mesecons_mvps
          - mesecons_noteblock
          - mesecons_pistons
          - mesecons_powerplant
          - mesecons_pressureplates
          - mesecons_random
          - mesecons_receiver
          - mesecons_solarpanel
          - mesecons_stickyblocks
          - mesecons_switch
          - mesecons_torch
          - mesecons_walllever
          - mesecons_wires
          - mobkit
          - mokapi
          - moreblocks
          - morelights
          - morelights_extras
          - morelights_modern
          - morelights_vintage
          - moreores
          - moretrains_basic
          - moretrains_industrial
          - moretrains_japan
          - moretrains_steam
          - moretrains_vintage
          - moretrees
          - my_castle_doors
          - my_cottage_doors
          - my_default_doors
          - my_door_wood
          - my_fancy_doors
          - my_future_doors
          - my_garage_door
          - my_hidden_doors
          - my_misc_doors
          - my_old_doors
          - my_saloon_doors
          - my_sliding_doors
          - ontime_clocks
          - orienteering
          - petz
          - pie
          - pipeworks
          - plasmascreen
          - protector
          - serialize_lib
          - shields
          - signs
          - signs_api
          - signs_lib
          - signs_road
          - stained_glass
          - steles
          - street_signs
          - streetlights_api
          - streetlights_lamps
          - streetlights_poles
          - streets
          - tfl_s7stock
          - travelnet
          - ts_workshop
          - unified_inventory
          - unifiedbricks
          - unifieddyes
          - waffles
          - wield3d
          - wieldview
        disabled_mods:
          - advtrains_itrainmap
          - advtrains_luaautomation
          - skinsdb
          - snowdrift

  tasks:
    - name: Stop minetest
      systemd:
        name: "{{ item }}"
        state: stopped
      become: true
      with_items:
        - minetest
        - mapserver

    - name: Copy local world
      ansible.builtin.copy:
        src: "/home/peter/.minetest/worlds/kifserver/{{ item }}"
        dest: "/var/lib/minetest/world/{{ item }}"
        mode: u=rw,g=r,o=r
        owner: minetest
        group: minetest
      become: true
      with_items:
        - advtrains_atc
        - advtrains_interlocking_influence_points
        - advtrains_interlocking_npr_rails
        - advtrains_interlocking_rs_callbacks
        - advtrains_interlocking_rs_locks
        - advtrains_interlocking_signalass
        - advtrains_interlocking_tcbs
        - advtrains_interlocking_ts
        - advtrains_lines
        - advtrains_luaautomation
        - advtrains_ndb
        - advtrains_ndb2
        - advtrains_ptmap
        - advtrains_trains
        - advtrains_version
        - advtrains_wagon_save
        - areas.dat
#        - auth.sqlite
        - beds_spawns
        - death_markers.json
        - env_meta.txt
        - force_loaded.txt
        - homes
        - ipban.txt
        - luaentities
        - map.sqlite
        - map_meta.txt
#        - mapserver.json
        - mapserver.sqlite
        - mesecon_actionqueue
        - mod_travelnet.data
        - players.sqlite
        - teleport_tubes
        - unified_inventory_home.home
#        - world.mt
      register: world

    - name: Copy mods stuff and map tiles
      ansible.posix.synchronize:
        src: "/home/peter/.minetest/worlds/kifserver/{{ item }}"
        dest: "/var/lib/minetest/world/{{ item }}"
        recursive: true
        checksum: true
      become: true
      with_items:
        - mod_storage
        - mapserver.tiles

    - name: Start minetest
      systemd:
        name: "{{ item }}"
        state: started
      become: true
      with_items:
        - minetest
        - mapserver
