Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ansible one liners
###Deploy SSH key to ansible inventory###
for server in $(ansible --list-hosts all); do ssh-copy-id -i ~/.ssh/ $server; done
Copy link

bcoca commented Oct 28, 2013

this way its also parallel to # of forks you use in ansible:

ansible -m authorized_key -a "key=\"{{lookup('file','~/.ssh/')}}\" user=$USER" all

Copy link

mflanneryii commented Dec 11, 2013

Alternatively if you've got SSHPass installed you can put the password in a clear text file (temporarily, and don't forget your chmod 600 before and shred when done) and then use the following (change the -P10 to the match the number of forks you want to run):

ansible all --list-hosts | xargs -n1 -P10 sshpass -f temporary_password_file ssh-copy-id -i ~/.ssh/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment