- name: Manage zimbot simulation machine
  hosts: zimbot_sim_3d
  tasks:
    - name: NTP sync ai with sim
      become: yes
      shell: 'chronyc makestep'
      tags:
        - ntp_sync

    - name: Launch 3D sim on sim machine
      script: sim_3d_files/start_sim.sh "{{ driving_repo }}" "{{ sim_scenario }}"
      tags:
        - start_sim

    - name: Launch roscore and ros dds bridge
      script: sim_3d_files/start_bridge.sh "{{ driving_repo }}"
      tags:
        - start_bridge

    - name: Shutdown 3D sim on sim machine
      script: sim_3d_files/stop_sim.sh
      tags:
        - stop_sim

    - name: Clean previous process
      script: sim_3d_files/clean_prev_process.sh
      tags:
        - clean_prev_process

    - name: Clear logs from previous run in ~/.log/
      become: yes
      shell: 'find /home/zoox/.log/{{ item }} -mindepth 1 -delete'
      with_items:
        - "ros"
        - "python"
        - "ftrace"
        - "electron"
        - "perf"
        - "glog"
      tags:
        - delete_prev_logs

    - name: Synchronize calibration repo on sim machine
      script: sim_3d_files/calibration_sync.sh "{{ calibration_repo }}" "{{ calibration_sha }}"
      tags:
        - calibration_sync

    - name: Synchronize driving repo on sim machine
      script: sim_3d_files/driving_sync.sh "{{ driving_repo }}" "{{ driving_sha }}"
      tags:
        - driving_sync

    - name: Downloading sim cache tiles
      script: sim_3d_files/pre_cache_sim_tiles.sh "{{ driving_repo }}" "{{ sim_scenario }}"
#      register: script_output
      tags:
        - pre_cache_sim_tiles

    - name: Debug print
      debug:
        var: script_output
      tags:
        - debug_print
