# Simple ansible playbook to deploy a chosen ingest_pkg_tar from Artifactory
---
- name: SSH into hosts and run command
  hosts: '{{ host_group }}'
  user: zoox
  gather_facts: yes
  tasks:

  - name: Print some debug information
    debug:
      msg:
        - "Hostname: {{ ansible_hostname }}"
        - "IP Address: {{ ansible_host }}"
        - "Host Distribution: {{ ansible_distribution }}"
        - "Host Dist version: {{ ansible_distribution_version }}"

  - name: Pull ingest tar package and extract into /opt/zoox/ingest
    unarchive:
      src: "{{ artifactory_url }}"
      dest: /opt/zoox/ingest
      remote_src: yes

  - name: Update file perms on script
    file:
      path: /opt/zoox/ingest/zoox/data/vehicle_data_sync/run_vehicle_data_sync_script.sh
      owner: zoox
      group: zoox
      mode: '744'

  - name: Move ingest wrapper script into place
    command: mv /opt/zoox/ingest/zoox/data/vehicle_data_sync/run_vehicle_data_sync_script.sh /opt/zoox/ingest

  - name: Copy file version to /etc/zoox/ingest_deploy_version
    copy:
      dest: /etc/zoox/ingest_deploy_version
      content: "{{ tar_filename }}\n"

  - name: Restart postfix
    service:
      name: postfix
      state: restarted
    become: yes
