Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Rsync tty issues #115

Open
petems opened this issue Jul 24, 2014 · 13 comments
Open

Rsync tty issues #115

petems opened this issue Jul 24, 2014 · 13 comments

Comments

@petems
Copy link

petems commented Jul 24, 2014

Hello!

So, trying to kick up a new Rackspace server. Config looks a little like this:

require 'yaml'
require_relative "vagrant_requires.rb"

# Looking at a credentail file as opposed to having it in the config file
RS_CONFIG = YAML.load_file(ENV['HOME']+'/.rax_cred')
RS_USER = RS_CONFIG['rackspace']['user']
RS_KEY = RS_CONFIG['rackspace']['api_key']

# Setting a shell variable to default to Rackspace as the provider
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'rackspace'

Vagrant.configure("2") do |config|

  config.puppet_install.puppet_version = :latest
  config.vm.box = "benhamine/dummy"

  config.vm.provider :rackspace do |rs, override|
    rs.username = RS_USER
    rs.api_key  = RS_KEY
    rs.rackspace_region = :lon
    rs.flavor   = /512MB Standard Instance/
    rs.image    = /CentOS 6.5/
    rs.disk_config = "AUTO"
    rs.rackconnect = true
    rs.public_key_path = './keys/key.pub'
    override.vm.synced_folder ".", "/vagrant", type: "rsync"
  end

  config.ssh.pty = true

  config.ssh.private_key_path = './keys/key'

  config.vm.define "web" do |web|
    config.vm.provider :rackspace do |web|
      web.server_name = "web"
      web.key_name = 'Bootstrap_Key'
    end
    config.vm.provision "shell", path: "bootstrap.sh"
  end
end

Everythings all dandy, until it tries to rsync the current folder to /vagrant (the default option):

There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /Users/peterso/Projects/foo-project/
Guest path: /vagrant
There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /Users/peterso/Projects/foo-project/
Guest path: /vagrant
Command: rsync --verbose --archive --delete -z --copy-links --no-owner --no-group --rsync-path sudo rsync -e ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i  '/Users/peterso/Projects/foo-project/keys/bootstrap' --exclude .vagrant/ /Users/peterso/Projects/foo-project/ root@[REDACTED]:/vagrant
Error: Warning: Permanently added '[REDACTED]' (RSA) to the list of known hosts.
sudo: sorry, you must have a tty to run sudo
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at /SourceCache/rsync/rsync-42/rsync/io.c(452) [sender=2.6.9]

Side note: Would it be better to surround the -e argument in quotes to make it a bit more readable? Might make a separate issue for that...

This then works fine if I do a sed on the /etc/sudoers and remove the require tty line. But that's an extra step I'd rather avoid.

Could we an an extra step to either:

  1. Add -t -t to the ssh command to force tty
  2. Remove requiretty from the sudoers file
  3. Some other better idea 👍
@petems
Copy link
Author

petems commented Jul 24, 2014

I just noticed this in the README:

CentOS / RHEL (sudo: sorry, you must have a tty to run sudo)

The default configuration of the RHEL family of Linux distributions requires a tty in order to run sudo. Vagrant does not connect with a tty by default, so you may experience the error:

sudo: sorry, you must have a tty to run sudo
The best way to deal with this error is to upgrade to Vagrant 1.4 or later, and enable:

config.ssh.pty = true

I have that in the config, still no dice 👎

@maxlinc
Copy link
Contributor

maxlinc commented Jul 24, 2014

@petems I think rsync should be requesting the pty and it's not. So we should fix that, but in the meantime you might be able to work around this by using config.ssh.proxy_command.

Can you confirm your vagrant and vagrant-rackspace versions? There's legacy code in this project for older versions, but if you're running recent versions then the rsync code is actually in vagrant itself. Also, the proxy_command workaround might not work for older versions.

@petems
Copy link
Author

petems commented Jul 24, 2014

vagrant -v
Vagrant 1.6.3
vagrant plugin list | grep rackspace
vagrant-rackspace (0.1.9)

for the proxy command, can I do config.ssh.proxy_command = '-t'?

@maxlinc
Copy link
Contributor

maxlinc commented Jul 24, 2014

I think you need to give it a full command, but I haven't tested or fully read the ssh docs on ProxyCommands. Vagrant will pass it as "ssh -o ProxyCommand=#{proxy_command}".

If you want to understand it better or submit a PR directly to vagrant, here's the relevant chunk of code:
https://github.com/mitchellh/vagrant/blob/3c4e129fb8e48ab1a8369e393e387bec77b5ad2b/plugins/synced_folders/rsync/helper.rb#L56-L70

@petems
Copy link
Author

petems commented Jul 24, 2014

Yeah, I'm looking over the code now. Looks like theres not an easy fix, and the proxy command stuff doesnt seem to help it seems.

I'm thinking about adding a config option to this plugin to use this rsync provider, then I could add the -t option to this plugin, as I'm assuming it'll probably be easier and faster to get a PR merged into this codebase than Vagrant. Sound good?

@petems
Copy link
Author

petems commented Jul 24, 2014

Made a post on the vagrant google group: https://groups.google.com/forum/#!topic/vagrant-up/138eMq_v8Os 👍

@maxlinc
Copy link
Contributor

maxlinc commented Jul 24, 2014

assuming it'll probably be easier and faster to get a PR merged into this codebase than Vagrant. Sound good?

Not to me. I'd vote against the merge. I want to remove the legacy rsync code as soon as possible (i.e. as soon as we feel everyone is on Vagrant 1.5+) because having two different rsync implementations causes confusion (they don't have compatible configuration) and means bugs need to be fixed at least twice (vagrant and rackspace), and sometimes more (aws, openstack, digitalocean, etc).

A solution for "Remove requiretty from the sudoers file" is possible. My original tty workaround used Server Personalities to inject a cloud-init style script that removed the requiretty. It wasn't merged because config.ssh.tty Vagrant released config.ssh.tty, which was a simpler solution. I'll try to solve both requiretty and WinRM w/ a personality script.

In the meantime, if proxy_command doesn't work then "make a new image with the requiretty removed and use that as a base image" sounds like your best option.

@petems
Copy link
Author

petems commented Jul 24, 2014

Ok cool, I'd be interested in resurrecting either the personality change or the fog upload, both would be awesome additions made pretty general. I'm trying to refactor https://github.com/mitchellh/vagrant-rackspace/pull/48/files a bit to make it so you can give a general pre-req script that can be run (so we could sed the sudoers file) and seeing if I can make the personality one generic enough to take two parameters, so you can use it for lots of different uses! 👍

@maxlinc
Copy link
Contributor

maxlinc commented Jul 24, 2014

The script was just:
https://github.com/maxlinc/vagrant-rackspace/blob/c7049af1f7fa36c2bdf6d5340f476fadfa07c82f/resources/require_tty_workaround.sh

Unfortunately, a general pre-req script for "lots of different uses" probably won't work. There are three issues:

  • These scripts should be a last resort. The user experience for a Vagrant provisioner is much better. These scripts run on the server before Vagrant connects, and Vagrant has no way to see the output, detect failures, debug, or even verifying that the script ran at all.
  • Vagrant's goal is "portable development environments". We don't want to add provisioner-like behavior that doesn't work with other providers.
  • There are strict limits on the the script: it needs to be less than 1kb, and we can only upload a few files, including SSH keys.

So it's best to limit the scripts to the bare minimum to allow Vagrant to create usable connections, and let provisioners do the rest.

@petems
Copy link
Author

petems commented Jul 24, 2014

Ok, I see what you're saying.

What if I just resurrect that old pull-request and get it working, would that be ok? So it's just the tty fix for RedHat flavour stuff so rsync will work. I've found most of the code works fine, it's just a slight code change for the Fog SCP settings.

Related: do you know how to change the order that tasks are run in? I found even when running the script from your change script doesn't fix the RedHat issue, as it always runs the rsync folder regardless of the order in action.rb...

@bkc1
Copy link

bkc1 commented Oct 2, 2014

Is there any update on the vagrant-rackspace rsync/tty issue. I am unable to vagrant provision without this working. I am running vagrant 1.6.5 and vagrant-rackspace 0.1.9 via cygwin and seeing the following:

Host path: /cygdrive/c/Vagrant/work/rackspace_test/
Guest path: /vagrant
Command: rsync --verbose --archive --delete -z --copy-links --chmod=ugo=rwX --no-perms --no-owner --no-group --rsync-path sudo rsync -e ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i 'C:/cygwin64/home/XXX/.ssh/key' --exclude .vagrant/ /cygdrive/c/Vagrant/work/rackspace_test/ root@XXX.XXX.XXX.XXX:/vagrant
Error: Warning: Permanently added 'XXX.XXX.XXX.XXX' (RSA) to the list of known hosts.
sudo: sorry, you must have a tty to run sudo

I can run the slightly modified cmd(changed key to a cyg path) manually without the error, but it prompts for a PW and doesn't use key auth(for reasons I don't know):

#rsync --verbose --archive --delete -z --copy-links --chmod=ugo=rwX --no-perms --no-owner --no-group --rsync-path sudo rsync -e ssh -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i '/cygwin64/home/XXX/.ssh/key' --exclude .vagrant/ /cygdrive/c/Vagrant/work/rackspace_test/ root@XXX.XXX.XXX.XXX:/vagrant
root@XXX.XXX.XXX.XXX's password:

@dbshorter
Copy link

I was having this same problem and the config.ssh.pty = true wasn't fixing anything.

Like you I was using vagrant-rackspace 0.1.9. On a whim I decided to try downgrading to vagrant-rackspace 0.1.6 and suddenly everything started working. So try downgrading to a previous version.

@VMTrooper
Copy link
Contributor

+1 on version 0.1.6 working correctly for RHEL/CentOS images. I tried using the latest version available from vagrant plugin install vagrant-rackspace

If a fix has been merged, please produce a new version of the plugin installer.

If a fix has not been merged, please compare the tty code from 0.1.6 with 0.1.9 and provide an updated installer.

FYI, for anyone needing to install the older version of the plugin, here is the command:
vagrant plugin install --plugin-version "0.1.6" vagrant-rackspace

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants