Skip to content

Instantly share code, notes, and snippets.

@rothgar
Created October 24, 2013 05:37
Show Gist options
  • Save rothgar/7131900 to your computer and use it in GitHub Desktop.
Save rothgar/7131900 to your computer and use it in GitHub Desktop.
Ansible one liners
###Deploy SSH key to ansible inventory###
for server in $(ansible --list-hosts all); do ssh-copy-id -i ~/.ssh/id_rsa.pub $server; done
@bcoca
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/id_rsa.pub')}}\" user=$USER" all

@mflanneryii
Copy link

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/id_rsa.pub

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