---
- name: "Read zoox user's public key"
  slurp:
    src: "{{ asset_root_directory }}/home/zoox/.ssh/id_rsa.pub"
  register: zoox_user_public_key

- name: Populate authorized keys file for zoox user
  authorized_key:
    user: zoox
    state: present
    path: "{{ asset_root_directory }}/home/zoox/.ssh/authorized_keys"
    key: "{{ item }}"
    manage_dir: no
  with_items:
    - "{{ lookup('file', 'authorized_keys') }}"  # KI operator machines use this particular key
    - "{{ zoox_user_public_key['content'] | b64decode }}"
    - "{{ zoox_build_host_ssh_key | default([]) }}"  # For imaging CI

- name: Set permissions on authorized keys file for zoox user
  file:
    path: "{{ asset_root_directory }}//home/zoox/.ssh/authorized_keys"
    owner: "{{ zoox_uid }}"
    group: "{{ zoox_gid }}"
    mode: '600'
