- name: Install hosts file
  template:
    src: "{{ item }}"
    dest:  "{{ asset_root_directory }}/etc/{{ item }}"
    mode: '644'
    owner: root
    group: root
  become: yes
  with_items:
    - hosts_C3.2
    - hosts_C3.5

- set_fact:
    ssh_host_public_key_key_only: "{{ lookup('hashi_vault_cache', 'secret=secret/robot/ssh_host/' + zoox_robot_name)['ssh_public_key'].split()[1] }}"
  when: ssh_host_public_key_key_only is not defined

- name: Populate known hosts
  known_hosts:
    name: "{{ item.host }}"
    key: "{{ item.host }} {{ item.type }} {{ item.key }}"
    path: "{{ asset_root_directory }}/etc/ssh/ssh_known_hosts"
    state: present
  with_items:
    - { host: 'localhost', type: "ssh-rsa", key: "{{ ssh_host_public_key_key_only }}" }
    - { host: "{{ zoox_robot_name }}", type: "ssh-rsa", key: "{{ ssh_host_public_key_key_only }}" }
    - { host: 'git.zooxlabs.com', type: "ssh-rsa", key: "{{ git_zooxlabs_rsa }}" }
    - { host: 'git.zooxlabs.com', type: "ecdsa-sha2-nistp256", key: "{{ git_zooxlabs_ecdsa }}" }
    - { host: 'github.com', type: "ssh-rsa", key: "{{ github_rsa }}" }
  become: yes
