【问题标题】:Vagrant::Butcher "sudo: no tty present and no askpass program specified" when trying to "cat /etc/chef/client.pem"尝试“cat /etc/chef/client.pem”时,Vagrant::Butcher “sudo:没有 tty 存在,也没有指定 askpass 程序”
【发布时间】:2014-04-23 10:41:48
【问题描述】:

Ubuntu 10.04.1 LTS,带有 Vagrant 1.4.3 和 Vagrant::Butcher 2.1.5。

我在“vagrant up”结束时收到以下错误:

...
[2014-03-17T22:50:56+00:00] INFO: Chef Run complete in 245.448117502 seconds
[2014-03-17T22:50:56+00:00] INFO: Running report handlers
[2014-03-17T22:50:56+00:00] INFO: Report handlers complete

[Butcher] Creating /home/testuser/vagrant_test/.vagrant/butcher
[Butcher] Failed to create /home/testuser/vagrant_test/.vagrant/butcher/DEV-35-51-client.pem: Vagrant::Errors::VagrantError - The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cat /etc/chef/client.pem

Stdout from the command:



Stderr from the command:

sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts

Chef 客户端成功运行,我们的说明书都已安装。其中之一是 sudo 社区食谱,我认为我们删除了 vagrant 用户需要执行 cat 才能阅读的条目client.pem 文件。

谁能告诉我那可能是什么?

更新:

1) vagrant 用户属于“sudo”组:

$ grep sudo /etc/group
sudo:x:27:vagrant

2) sudoers 文件包含一个让“sudo”组运行任何命令的条目:

# This file is managed by Chef.
# Do NOT modify this file directly.

Defaults      env_reset
Defaults      secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# User privilege specification
root      ALL=(ALL:ALL) ALL
nagios    ALL=(ALL) NOPASSWD: /usr/local/nagios/libexec/


# Members of the group 'admin' may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo     ALL=(ALL:ALL) ALL

#includedir /etc/sudoers.d

【问题讨论】:

  • 那么...为什么不在 vagrant-butcher 插件上报告这个? github.com/cassianoleal/vagrant-butcher
  • sudo 组具有 sudo 访问权限,但它不是无密码的。 @tmatilai 的回答似乎很到位。

标签: chef-infra vagrant sudo


【解决方案1】:

这最终不是一个流浪屠夫的问题;该插件只是碰巧首先遇到了问题。此外,任何后续的 vagrant 操作也会失败。

Vagrant 需要无密码的 sudo 权限。似乎基本框在 /etc/sudoers 中声明了它,您用 sudo 食谱覆盖了它。

您至少有以下选择:

  1. node['authorization']['sudo']['passwordless'] 属性设置为true。
  2. 根本不包括 sudo 食谱的默认配方。
  3. 使用 sudo LWRP 向 vagrant 用户授予无密码 sudo 访问权限。
  4. 使用或构建一个已经使用 /etc/sudoers.d/ 的基础框。

【讨论】:

  • 不完全确定为什么,但我必须做 #1 和 #4
【解决方案2】:

tmatilai 很好地解决了这个问题,但是我想我会在这里发布我的解决方案以供将来参考。我找到了与他提到的选项 #3 相同的解决方法,为 vagrant 用户编写一个添加 sudoers.d 配置文件的配方。这迫使我修改 sudo 社区食谱以支持 SETENV 选项。否则你会得到错误:

sudo: sorry, you are not allowed to preserve the environment

生成的文件是 /etc/sudoers.d/vagrant,注意它需要 NOPASSWD 和 SETENV:

# This file is managed by Chef.
# Do NOT modify this file directly.

vagrant  ALL=(ALL) NOPASSWD:SETENV: /bin/

以下是我所做的更改:

文件:sudo/recipes/default.rb

# if the node belongs to the "development" environment, create a config file
# for the vagrant user, e.g. /etc/sudoers.d/vagrant
if node.chef_environment == 'development'
  sudo 'vagrant' do
    user      'vagrant'
    runas     'ALL'  # can run as any user
    host      'ALL'  # from any Host/IP
    nopasswd  true   # prepends the runas_spec with NOPASSWD
    setenv    true   # prepends the runas_spec with SETENV
    commands  ['/bin/']  # let the user run anything in /bin/ without a password
  end
end

文件:sudo/resources/default.rb

# add new attribute "setenv"
attribute :setenv,     :equal_to => [true, false],  :default => false

# include it in the state_attrs list
state_attrs :commands,
            :group,
            :host,
            :nopasswd,
            :setenv,
            :runas,
            :template,
            :user,
            :variables

文件:sudo/providers/default.rb

# in render_sudoer, add setenv to the variables list
variables     :sudoer => sudoer,
              :host => new_resource.host,
              :runas => new_resource.runas,
              :nopasswd => new_resource.nopasswd,
              :setenv => new_resource.setenv,
              :commands => new_resource.commands,
              :defaults => new_resource.defaults

文件:sudo/templates/default/sudoer.erb

# generate SETENV option in the config file entry
<% @commands.each do |command| -%>
<%= @sudoer %>  <%= @host %>=(<%= @runas %>) <%= 'NOPASSWD:' if @nopasswd %><%= 'SETENV:' if @setenv %> <%= command %>
<% end -%>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 2015-11-06
    • 2014-11-18
    • 2021-10-26
    • 2015-02-21
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多