Unable to perform ssh-copy-id after installing the gem

I am trying to copy authentication files onto the remote server using ssh-copy-id.In order to perform that I have installed ssh-copy-id.rb ruby gem and trying to perform copy with the following code

ruby_block ‘olcTLSCertificateFile_1’ do
block do
ssh-copy-id.rb -i ~/.ssh/id_dsa.pub -u username -p password remote_user@hostname:22
end
end

but the above code is returning an error specifying ssh-copy-id.rb: not found

Could anyone help me on resolving this issue.

You are trying to run a shell command in a ruby_block as it seems. Please see the docs for the two resources execute [1] and ruby_block [2] on how to run commands via chef.

[1] http://devdocs.io/chef~12/12-13/resource_execute
[2] http://devdocs.io/chef~12/12-13/resource_ruby_block

Hi joerg, thanks for your response. I have tried both execute and ruby_block resources but none of them helped and both are resulting in the same error.

In this case we need some more debug info:

  • Does calling the ssh-copy-id.rb command manually from a command line work?
  • How exactly do/did you install the ssh-copy-id.rb gem?
  • What exactly is the error? Please copy paste some relevant error messages here.
  • Which version of Chef are you running and how did you install it (RPM, Omnibus etc)?

I have installed the gem package using chef_gem resource

with ruby_block It is simply showing runsh: 1: ssh-copy-id.rb: not found error

with execute resource I am getting the following error

Caused by Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of ssh-copy-id.rb -i ~/.ssh/id_dsa.pub -u username -p password username@hostname:22 ----
STDOUT:
STDERR: sh: 1: ssh-copy-id.rb: not found

Well, you actually did not answer the most important Question:

  • Does calling the ssh-copy-id.rb command manually from a command line work?

and also not

  • Which version of Chef are you running and how did you install it (RPM, Omnibus etc)?

Both of them are actually quite crucial and in your case I think they would answer what the problem is.
But I think I know where the problem is. If you install a gem via chef_gem it gets installed within the chef context, so the ssh-copy-id.rb is in /opt/chef/embedded/bin which pretty sure is not in your PATH, right?

Hello joerg, thanks for your support it didn’t worked for me and I found an alternative with sshpass and ssh-copy-id itself which resolved my issue.