Skip to content

Instantly share code, notes, and snippets.

@colorstain
Last active July 18, 2016 15:58
Show Gist options
  • Save colorstain/79aa4180cebb7992ee9f445e15bc653f to your computer and use it in GitHub Desktop.
Save colorstain/79aa4180cebb7992ee9f445e15bc653f to your computer and use it in GitHub Desktop.
Copy SSH Keys to remote servers
---
- name: Copy SSH key
hosts: all
serial: "{{ serial|default(1) }}"
tasks:
- name: Get the name of the user running the script
local_action: command whoami
register: username_on_host
- name: Copy ssh key to server
authorized_key:
user: "{{ username_on_host.stdout }}"
key: "{{ lookup('file', '/Users/{{ username_on_host.stdout }}/.ssh/id_rsa.pub') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment