为什么这个由 Vagrant 配置的 AWS 实例一启动就会终止?

为什么这个由 Vagrant 配置的 AWS 实例一启动就会终止?

我的 Vagrant 配置的 AWS 实例一旦启动就会终止。

这是我的配置文件:

  config.vm.box = "aws-dummy"
  config.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"

  config.vm.synced_folder "./", "/vagrant", type: "rsync"


  config.vm.provider :aws do |aws, override|
    aws.access_key_id = "MY ID"
    aws.secret_access_key = "MY SECRET KEY GOES HERE"
    aws.keypair_name = "cb"
    aws.ami = "ami-f77fbeb3"
    aws.instance_ready_timeout = 300
    aws.instance_type = "t2.small"
    aws.tags = {
        "Name" => "VagrantUniversal",
    }

    aws.associate_public_ip = true
    aws.availability_zone = "us-west-1a"
    aws.subnet_id = "subnet-f2245XXX"

    aws.private_ip_address = "10.1.10.10"
    aws.security_groups = [ 'sg-4084dXXX' ] # 
    aws.region = "us-west-1"
    # aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => 50 }]

    override.ssh.username = "centos"
    override.ssh.private_key_path = "../keys/cb.pem"
  end

我删除了配置部分以消除这种可能性。我还尝试注释掉 synced_folder

从日志中:

 INFO interface: info: Machine is booted and ready for use!
 INFO interface: info: ==> default: Machine is booted and ready for use!
==> default: Machine is booted and ready for use!
 INFO warden: Calling IN action: #<Proc:0x00000100a3d5f8@/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/warden.rb:94 (lambda)>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::Call:0x000001028a1058>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Builder:0x00000100a4e290>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Extras::Action::DNS::ProviderIsAWS:0x00000100a57368>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Extras::Action::DNS::ProviderIsAWS:0x00000100a57368>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Warden:0x00000100a859e8>
 INFO warden: Calling IN action: #<Proc:0x000001023ca7f0@/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/warden.rb:94 (lambda)>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x00000100a85970>
 INFO connect_aws: Connecting to AWS...
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ReadSSHInfo:0x00000102968220>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Extras::Action::DNS::ConnectAWS:0x000001029a1160>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Extras::Action::DNS::Set:0x000001029da5f0>
ERROR warden: Error occurred: undefined method `records' for nil:NilClass
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: undefined method `records' for nil:NilClass
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
ERROR warden: Error occurred: undefined method `records' for nil:NilClass
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x000001028a1058>
 INFO warden: Beginning recovery process...
 INFO warden: Recovery complete.
 INFO warden: Calling recover: #<Vagrant::Action::Builtin::Call:0x000001028a10a8>
 INFO warden: Beginning recovery process...
 INFO warden: Calling recover: #<VagrantPlugins::AWS::Action::RunInstance:0x00000100a17650>
 INFO machine: Calling action: read_state on provider AWS (i-41bcaa81)
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 2 hooks defined.
 INFO runner: Running action: machine_action_read_state #<Vagrant::Action::Builder:0x00000104342c90>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::ConfigValidate:0x000001043480a0>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x00000104348028>
 INFO connect_aws: Connecting to AWS...
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ReadState:0x000001043a9f30>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Action::ReadState:0x000001043a9f30>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x00000104348028>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::ConfigValidate:0x000001043480a0>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Builder:0x000001009a6068>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::Call:0x000001009b4e60>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Builder:0x00000100a1f0a8>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::DestroyConfirm:0x00000100a1c290>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::DestroyConfirm:0x00000100a1c290>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Warden:0x00000100a54dc0>
 INFO warden: Calling IN action: #<Proc:0x00000100a96d88@/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/warden.rb:94 (lambda)>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::ConfigValidate:0x00000100a54d48>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::Call:0x00000100a54d20>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Builder:0x000001029bb920>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::IsCreated:0x000001029b8180>
 INFO machine: Calling action: read_state on provider AWS (i-41bcaa81)
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 2 hooks defined.
 INFO runner: Running action: machine_action_read_state #<Vagrant::Action::Builder:0x00000101036a40>
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::ConfigValidate:0x0000010283bd20>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x0000010283baf0>
 INFO connect_aws: Connecting to AWS...
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ReadState:0x000001022c69f8>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Action::ReadState:0x000001022c69f8>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x0000010283baf0>
 INFO warden: Calling OUT action: #<Vagrant::Action::Builtin::ConfigValidate:0x0000010283bd20>
 INFO warden: Calling OUT action: #<VagrantPlugins::AWS::Action::IsCreated:0x000001029b8180>
 INFO runner: Preparing hooks for middleware sequence...
 INFO runner: 3 hooks defined.
 INFO runner: Running action: machine_action_up #<Vagrant::Action::Warden:0x000001040a93a8>
 INFO warden: Calling IN action: #<Proc:0x0000010432b7c0@/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/warden.rb:94 (lambda)>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ConnectAWS:0x000001040a9218>
 INFO connect_aws: Connecting to AWS...
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::ElbDeregisterInstance:0x00000104179990>
 INFO warden: Calling IN action: #<VagrantPlugins::AWS::Action::TerminateInstance:0x000001028962e8>
 INFO interface: info: Terminating the instance...
 INFO interface: info: ==> default: Terminating the instance...
==> default: Terminating the instance...
 INFO machine: New machine ID: nil
 INFO warden: Calling IN action: #<Vagrant::Action::Builtin::ProvisionerCleanup:0x000001042392b8>
 INFO warden: Calling IN action: #<Proc:0x000001042c1258@/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/action/warden.rb:94 (lambda)>

...这是不带调试信息的日志的要点:

==> default: Launching an instance with the following settings...
==> default:  -- Type: t2.small
==> default:  -- AMI: ami-f77fbeb3
==> default:  -- Region: us-west-1
==> default:  -- Availability Zone: us-west-1a
==> default:  -- Keypair: cb
==> default:  -- Subnet ID: subnet-f2245XXX
==> default:  -- Private IP: 10.1.10.10
==> default:  -- Security Groups: ["sg-4084dXXX"]
==> default:  -- Block Device Mapping: []
==> default:  -- Terminate On Shutdown: false
==> default:  -- Monitoring: false
==> default:  -- EBS optimized: false
==> default:  -- Assigning a public IP address in a VPC: true
==> default: Waiting for instance to become "ready"...
==> default: Waiting for SSH to become available...
==> default: Machine is booted and ready for use!
==> default: Terminating the instance...
/Users/swirsky/.vagrant.d/gems/gems/vagrant-aws-extras-0.1.0/lib/vagrant-aws-extras/action/dns.rb:61:in `call': undefined method `records' 
for nil:NilClass (NoMethodError)

我正在运行 Vagrant v1.7.4、vagrant-aws(0.6.0)、vagrant-aws-extras(0.1.0)、ruby 2.0.0p481

如果我删除该vagrant-aws-extras插件,我会收到这个奇怪的消息:

mkdir -p'/vagrant'

来自命令的标准输出:

命令中的 Stderr:

sudo:抱歉,您必须有一个 tty 才能运行 sudo

以下 SSH 命令以非零退出状态响应。Vagrant 认为这意味着命令失败!mkdir -p '/vagrant'

来自命令的标准输出:

命令中的 Stderr:sudo:抱歉,您必须有一个 tty 才能运行 sudo

答案1

这可能是vagrant-aws-extras插件的一个错误,因为其他人也报告了这个问题,请参阅:GH vagrant-aws #442。或者可能是您的图像框配置错误。

因为不清楚你调用的是哪个命令,但如果调用vagrant reload,它会按照设计终止您的实例,因为它只是运行一个,halt然后运行一个up,所以这是正常的。然而问题是它没有正确启动,因为出现以下错误:

sudo:抱歉,您必须有一个 tty 才能运行 sudo

我遇到了类似的问题,reload已报告GH 流浪者 #7244

因此,解决方法是销毁机器并重新配置。或者,如果您想在正在运行的实例上再次运行配置,只需运行vagrant provision即可避免调用关机命令。

问题也可能不是由关机命令本身引起的,而是由运行时出现的上述错误引起的mkdir -p '/vagrant'

最好使用不需要 tty 和 sudo 的镜像。否则请将镜像配置为不需要密码,因为 Vagrant 默认假定该sudo命令不需要输入密码。

注释掉Defaults requirettyfrom也/etc/sudoers可能有帮助。或者使用config.ssh.pty = true选项来获取 tty。

看:GH #1482 for vagrant - 无法在需要 tty 运行 sudo 的机器上执行 sudo 命令

相关内容