Skip to content

Instantly share code, notes, and snippets.

@vicendominguez
Last active February 16, 2018 23:22
Show Gist options
  • Save vicendominguez/367bf31b5d2ee83ac472 to your computer and use it in GitHub Desktop.
Save vicendominguez/367bf31b5d2ee83ac472 to your computer and use it in GitHub Desktop.
Ansible: playing with pubkeys and sync files
- name: Generating RSA key for root
user: name=root generate_ssh_key=yes
- name: Downloading pub key
fetch: src=/root/.ssh/id_rsa.pub dest=/tmp/id_rsa.tmp flat=yes
- name: Copying local key to other.server.net
local_action: shell cat /tmp/id_rsa.tmp | ssh -p 2244 root@other.server.net "cat >> /root/.ssh/authorized_keys"
- name: Deleting temporal files
local_action: file path=/tmp/id_rsa.tmp state=absent
- name: Coping local key to other.server.net
local_action: shell cat /tmp/id_rsa.tmp | ssh -p 2244 root@other.server.net "cat >> /root/.ssh/authorized_keys"
- name: Removing temporal keys from other.server.net
shell: ssh -p 2244 root@other.server..net 'sed -i "/ansible-generated/d" /root/.ssh/authorized_keys'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment