pstadler / flightplan

Run sequences of shell commands against local and remote hosts.
https://www.npmjs.com/package/flightplan
MIT License
1.82k stars 116 forks source link

Using .ssh/config during rsync #117

Closed monofonik closed 8 years ago

monofonik commented 8 years ago

Is there a way to just use the current user's .ssh/config instead of specifying everything in plan.target?

Here's the relevant part of my .ssh/config:

Host web.xyz.local
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile ....
  IdentitiesOnly yes
  LogLevel FATAL

I can rsync to my target machine from the command line successfully like this:

rsync -r test vagrant@web.xyz.local:

However the rsync command during deployment prompts for a password:

localhost Copy files to remote hosts
localhost $ cd /var/folders/54/w19fz8zx4p921svq3j73w0nm0000gn/T/devkit-1454197722953 && find .
localhost ● ok
localhost $ cd /var/folders/54/w19fz8zx4p921svq3j73w0nm0000gn/T/devkit-1454197722953 && rsync --files-from /var/folders/54/w19fz8zx4p921svq3j73w0nm0000gn/T/37bde9a6bd1984339ab9b8e012c383ea -az --rsh="ssh -p2222" ./ vagrant@web.xyz.local:/var/www/adserver/rsync/ --delete
Password: 

Am I missing something here?

pstadler commented 8 years ago

This is odd, .ssh/config should be read when using rsync with --rsh.

Do you have the same problem when using rsync --rsh="ssh -p2222" -r test vagrant@web.xyz.local:?

pstadler commented 8 years ago

To answer the other part of the question: It is possible to use a library to read .ssh/config and create the target configuration on the fly. If the library of your choice parses the configuration asynchronously, you can use dynamic host configuration.

Please note that Flightplan was built around the idea of having a config that's being shared by a team and not everybody has the same local setup.

Let me know if you need further assistance, otherwise I would be glad if you could put your solution here, so it could be added to the README or even built in as a core functionality.

monofonik commented 8 years ago

Thanks for your reply.

Yes executing rsync --rsh="ssh -p2222" -r test vagrant@web.xyz.local: works as expected. I'll post here if / when I have a solution. Thanks for the tip re. reading the .ssh/config, will go down that path if necessary.

Cheers

pstadler commented 8 years ago

@monofonik did you manage to solve this? How about sharing some code for the docs or wiki?

monofonik commented 8 years ago

Not solved yet unfortunately, although I think the problem may only be affecting my Mac environments. Will report back here when I have more detailed info.

monofonik commented 8 years ago

This was a bit of a red herring - you might have noticed by some details provided above that this error was occurring in the context of deploying to a Vagrant VM.

I've managed to solve this by not using the port forwarded by vagrant for SSH. Instead I just configure flightplan to connect directly to the Vagrant VM on the standard SSH port (22) which my VM config exposes.

theY4Kman commented 7 years ago

I just published flightplan-sshconf to provide this functionality. Hope it helps :)

pstadler commented 7 years ago

That's great! :-)