---

- name: Add imaging bin to PATH and set VAULT_ADDR
  lineinfile:
    line: "{{ item }}"
    path: /home/zoox/.profile
    create: yes
    owner: zoox
    group: zoox
  with_items:
    - export PATH="{{ imaging_bin }}:$PATH"
    - export VAULT_ADDR="{{ vault_address }}"
    - export PYTHONPATH="/home/zoox/driving/"

- name: Create .ssh directory
  file:
    path: /home/zoox/.ssh
    state: directory
    mode: '700'
    owner: zoox
    group: zoox


- name: Install ssh config
  template:
    src: ssh_config
    dest: /home/zoox/.ssh/config
    backup: yes
    owner: zoox
    group: zoox

- name: Package zimage application
  delegate_to: localhost
  command:
    cmd: "./setup.py sdist"
    chdir: "../../"

- name: Copy tarball
  copy:
    src: ../../dist/imaging-0.1.tar.gz
    dest: /tmp

- name: Install zimage python package
  pip:
    executable: pip3.6
    name: file:///tmp/imaging-0.1.tar.gz
    state: forcereinstall
    extra_args: "--no-dependencies"
  become: yes

- name: Install zimage python package dependencies
  pip:
    executable: pip3.6
    name: file:///tmp/imaging-0.1.tar.gz
  become: yes

- name: Install zimage entrypoint
  copy:
    src: "zimage"
    dest: "{{ imaging_bin }}zimage"
    owner: zoox
    group: zoox
    mode: '755'

- name: Populate source checksums file
  copy:
    content: "{{ lookup('imaging_common', 'compute_all_source_checksums') | to_nice_json(indent=4) }}\n"
    dest: "{{ imaging_assets }}/imaging_source_checksums.json"
    owner: zoox
    group: zoox
  tags: write_imaging_source_checksums_file
