Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you cope with distros having requiretty enabled in /etc/sudoers #24

Open
rubiojr opened this issue Sep 5, 2012 · 6 comments
Open

Comments

@rubiojr
Copy link

rubiojr commented Sep 5, 2012

Hey Delano,

Having issues with:

box = Rye::Box.new host, args
box.sudo 'my-foo-command'

or

box = Rye::Box.new host, args
box.enable_sudo
box.execute 'my-bar-command'  

when /etc/sudoers has "Defaults requiretty" (like CentOS):

/home/rubiojr/.rvm/gems/ruby-1.9.3-p194/gems/rye-0.9.7/lib/rye/box.rb:855:in `rescue in run_command': sudo: sorry, you must have a tty to run sudo (cmd: sudo cat /etc/issue; status: 1) (Rye::Err)
    from /home/rubiojr/.rvm/gems/ruby-1.9.3-p194/gems/rye-0.9.7/lib/rye/box.rb:806:in `run_command'
    from /home/rubiojr/.rvm/gems/ruby-1.9.3-p194/gems/rye-0.9.7/lib/rye/box.rb:597:in `sudo'
        ...

Haven't been able to find a good way to cope with this without patching. Any hints?

@rubiojr
Copy link
Author

rubiojr commented Sep 5, 2012

Not really sure of the consequences but anyway, here's the patch that works for me:

--- /home/rubiojr/.rvm/gems/ruby-1.9.3-p194/gems/rye-0.9.7/lib/rye/box.rb   2012-09-06 00:31:52.393855539 +0200
+++ /home/rubiojr/.rvm/gems/ruby-1.9.3-p194/gems/rye-0.9.7/lib/rye/box.rb.new   2012-09-06 00:31:34.417766396 +0200
@@ -894,7 +894,7 @@
                               :modes       => {} }

       channel = @rye_ssh.open_channel do |channel|
-        if self.rye_shell && blk.nil?
+        if (self.rye_shell && blk.nil?) or sudo?
           channel.request_pty(pty_opts) do |ch,success|
             self.rye_pty = success
             raise Rye::NoPty if !success

@rubiojr
Copy link
Author

rubiojr commented Sep 5, 2012

Looks like that's only part of the equation unfortunately, since box.sudo? evals to false when using box.sudo instead of box.enable_sudo and then running the command with execute.

@delano
Copy link
Owner

delano commented Sep 19, 2012

I don't have any solution for this currently unfortunately (other than to update the sudoers config).

@rberger
Copy link

rberger commented Jun 4, 2013

Anything new on this? I also have a situation where I need to ship a program to 3rd parties and can't control the Sudoers file. It looks like Centos 6 at least sets requiretty as the default.

@rubiojr
Copy link
Author

rubiojr commented Jun 5, 2013

@rberger I did find a solution to the problem and I've been using it with CentOS boxes since then:

https://github.com/rubiojr/shexy/blob/master/lib/shexy.rb#L104

@ms-ati
Copy link

ms-ati commented May 8, 2015

If you are using an Amazon linux AMI that supports user data, it's probably best to just change the sudoers config like this: hashicorp/vagrant#1482 (comment)

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

No branches or pull requests

4 participants