Last active
February 16, 2018 23:22
-
-
Save vicendominguez/367bf31b5d2ee83ac472 to your computer and use it in GitHub Desktop.
Ansible: playing with pubkeys and sync files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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