---
- name: 'upload ssh keys for root access to hetzner cloud'
  hosts: '{{ host | default("all") }}'
  gather_facts: false
  connection: local

  pre_tasks:
    - name: "add ssh key for root access"
      hetzner.hcloud.hcloud_ssh_key:
        api_token: "{{ hetzner_authentication_ansible }}"
        name: "{{ lookup('file', 'users/' + item + '/ssh.pub').split(' ') | last }}"
        public_key: "{{ lookup('file', 'users/' + item + '/ssh.pub') }}"
        state: "{{ ssh_key_state | default('present') }}"
      loop: '{{ hetzner_ssh_keys }}'
      run_once: true
