--- # Playbook: ssh-keys # Purpose: Install your workstation SSH public key on all inventory hosts # Targets: all hosts except localhost # Usage: make copy-ssh-keys-ansible # make copy-ssh-keys-ansible GROUP=services # make copy-ssh-keys-ansible HOST=dev01 - name: Deploy workstation SSH public key hosts: all:!local gather_facts: false vars: ssh_public_key_file: "{{ lookup('env', 'SSH_PUBLIC_KEY') | default(lookup('env', 'HOME') + '/.ssh/id_ed25519.pub', true) }}" tasks: - name: Add SSH public key for ansible_user ansible.posix.authorized_key: user: "{{ ansible_user | default(ansible_user_id) }}" state: present key: "{{ lookup('file', ssh_public_key_file) }}" become: false