mitchellh / vagrant-aws

Use Vagrant to manage your EC2 and VPC instances.
MIT License
2.61k stars 573 forks source link

"vagrant rsync" fails when executed in Jenkins on CentOS 6.5 running in AWS #293

Open cooniur opened 10 years ago

cooniur commented 10 years ago

Environment

EC2 AMI: (ami-8997afe0): https://aws.amazon.com/marketplace/pp/B00IOYDTV6/ref=srh_res_product_title?ie=UTF8&sr=0-5&qid=1411713770511 CentOS: 6.5 rsync: 3.0.6 vagrant-aws: 0.5.0 vagrant: 1.6.5 Jenkins: 1.581 override.ssh.pty = true i.e. using PTY (CentOS doesn't allow tty by default)

Summary

When running Vagrant in Jenkins, rsync 3.0.6 will fail on CentOS 6.5 when using vagrant-aws to spin up an EC2 instance.

Details

vagrant up ec2server --provider=aws was executed in Jenkins, but returned the error: failed to exec ssh: Permission denied (13). The ssh command is indeed /usr/bin/ssh. The user is tomcat, having the right permission to execute rsync as well as ssh.

Below is the output obtained by using VAGRANT_LOG=debug

DEBUG ssh: PTY stdout parsed: 
 INFO subprocess: Starting process: ["/usr/bin/rsync", "--verbose", "--archive", "-z", "--delete", "--exclude", ".vagrant/", "--exclude", "Vagrantfile", "-e", "ssh -p 22 -i '/home/tomcat/.ssh/keys/MyKey.pem'  -o 'StrictHostKeyChecking=no'", "/home/tomcat/vagrant-ec2/", "root@10.12.2.79:/vagrant"]
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stderr: rsync: Failed to exec ssh:    Permission denied (13)
DEBUG subprocess: stderr: 
DEBUG subprocess: stderr: rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.6]
DEBUG subprocess: stderr: 
DEBUG subprocess: stderr: rsync: connection unexpectedly    closed (0 bytes received so far) [sender]
DEBUG subprocess: stderr: 
DEBUG subprocess: stderr: rsync error: error in IPC code (code 14) at io.c(600) [sender=3.0.6]
DEBUG subprocess: stderr: 
DEBUG subprocess: Waiting for process to exit. Remaining to     timeout: 32000
DEBUG subprocess: Exit status: 14
ERROR warden: Error occurred: There was an error when   attempting to rsync a shared folder.
Please inspect the error message below for more info.

Analysis

I manually executed the command in bash in the same server:

rsync --verbose --archive -z --delete --exclude .vagrant/ --exclude Vagrantfile -e "ssh -p 22 -i '/home/tomcat/.ssh/keys/MyKey.pem' -o 'StrictHostKeyChecking=no'" /home/tomcat/vagrant-ec2/ root@10.12.2.79:/vagrant

and it can be executed successfully, i.e., files can be transferred to remote server.

So what did I miss?

Update

Temporary Workaround

Disable sync_folders by:

config.vm.synced_folder ".", "/vagrant", disabled: true
fonkap commented 7 years ago

I'm experiencing a similar issue with jenkins and rsync. This SO question seems related too: http://stackoverflow.com/questions/30743180/why-rsync-fails-with-jenkins

But the answer does not solve my problem.

fonkap commented 7 years ago

Yes! finally found the problem.

rsync was not being executed with the expected user (jenkins) but with another (jboss in my case) adding 'whoami' to the script and using ssh verbose:

rsync -e "ssh -v" .......

helped to find the problem.