Is the authorized_key module of ansible, can be used to copy the ssh keys of host to a new remote user?
0
votes
Why not use 'copy' for this?
– seanmcl
I would like to know, whether we could automate the initial connection set up with new the remote host. I guess, the copy module can be used only after the connection is set up.
– Vasu
I see, so rather than passing --private-key or using your own ssh config file to make the first connection, you want to use this module. Then I'm fairly sure the answer is no; you need to use the usual ansible mechanisms (ansible_ssh_private_key_file, etc.)
– seanmcl
1 Answers
1
votes
Ansible is completely over SSH. So you have to use ssh to setup ssh too. At minimum, you need a ssh daemon running and a user that can access the host with a password.
You can then access the host using -k
(or --ask-pass
, ask for SSH password), -K
(or --ask-sudo-pass
, ask for sudo password) and -u
(or --user
, connect as this user).
Let's say you have a foo
user that can ssh and sudo on the remote machine, and you want to install some ssh public key to login as root, you can do this :
ansible yourhost -kKu foo -m authorized_key -a "ssh-dss AAAAB...zzz [email protected]"
You'l be requested to type :
- foo's password on remote host
- password when foo is sudoing to root
See http://docs.ansible.com/authorized_key_module.html for alternate ways to read the local ssh key (lookup).