简体   繁体   English

使用AWS Cookbook InvalidInstanceIDNotFound的Chef EC2 EBS卷

[英]Chef EC2 EBS Volume Using AWS Cookbook InvalidInstanceIDNotFound

I'm using the Chef provided AWS cookbook (v2.7.2) to create and attach an EBS volume on an Ubuntu Server 14.04.02 LTS HVM ec2 instance during the initial bootstrapped chef-client run. 我正在使用Chef提供的AWS食谱 (v2.7.2)在初始引导的Chef-Client运行期间在Ubuntu Server 14.04.02 LTS HVM ec2实例上创建并附加EBS卷。 I'm hosting my own chef server (12.1.0-1_amd64). 我正在托管我自己的厨师服务器(12.1.0-1_amd64)。 Using knife-ec2, I create the aws instance and bootstrap the runlist via the following command: 使用knife-ec2,我创建了aws实例,并通过以下命令引导运行列表:

knife ec2 server create --region us-east-1 --availability-zone us-east-1a --node-name my-server --run-list "role[my-role]" --image ami-d05e75b8 --flavor c3.large --ebs-size 16 --ebs-volume-type gp2 --subnet subnet-mySubnetId --associate-public-ip --server-connect-attribute public_ip_address --ssh-user ubuntu --ssh-key my-pem --identity-file /path/to/my-pem.pem -y

However, when the recipe executes that creates and attaches the volume, the volume successfully creates, but fails to attach to my instance. 但是,当执行配方创建并附加卷时,该卷成功创建,但无法附加到我的实例。 The following error keeps occuring: 不断发生以下错误:

Aws::EC2::Errors::InvalidInstanceIDNotFound: The instance ID 'i-36a93b84' does not exist

The following code is in my recipe (taken from the example on the cookbook page): 以下代码在我的食谱中(摘自食谱页面上的示例):

include_recipe 'aws'

aws_ebs_volume "backup_volume" do
  aws_access_key aws['aws_access_key_id']
  aws_secret_access_key aws['aws_secret_access_key']
  size 16
  device "/dev/sdi"
  availability_zone "us-east-1a"
  action [ :create, :attach ]
end

I verified 'i-36a93b84' is the id of the instance knife-ec2 creates and the chef-client is executing on, so it does exist. 我确认'i-36a93b84'是knife-ec2创建的实例的ID,并且Chef-client正在执行,因此它确实存在。 Also, I validated that I'm creating the volume in the same availability zone as the instance. 另外,我验证了是否在与实例相同的可用区中创建卷。

I've read some posts about AWS's Eventual Consistency , but have no idea how to handle this during a bootstrapped chef-client run, since the recipe runs immediately after the instance is created. 我已经阅读了一些有关AWS的最终一致性的文章 ,但是不知道如何在自举厨师和客户端运行期间处理此问题,因为配方是在实例创建后立即运行的。

Is there a way to create an additional mount at the time knife-ec2 creates the aws server, or am I trying to attach a volume in an unorthodox manner? 在knife-ec2创建aws服务器时,是否有办法创建其他安装,还是我试图以非正统的方式附加卷?

Chef client output during the recipe: 食谱期间的厨师客户端输出:

Recipe: my-cookbook::backupvolume
      * aws_ebs_volume[backup_volume] action create[2015-07-17T11:57:05+00:00] INFO: Processing aws_ebs_volume[backup_volume] action create (my-cookbook::backupvolume line 49)
      [2015-07-17T11:57:05+00:00] DEBUG: Providers for generic aws_ebs_volume resource enabled on node include: [LWRP provider aws_ebs_volume from cookbook aws]
      [2015-07-17T11:57:05+00:00] DEBUG: Provider for action create on resource aws_ebs_volume[backup_volume] is LWRP provider aws_ebs_volume from cookbook aws
      [2015-07-17T11:57:05+00:00] DEBUG: Instance ID is i-36a93b84
      [2015-07-17T11:57:05+00:00] DEBUG: Instance's availability zone is us-east-1a
      [2015-07-17T11:57:05+00:00] DEBUG: Created new  volume vol-4842ecc4
      [2015-07-17T11:57:05+00:00] DEBUG: Volume is creating
      [2015-07-17T11:57:08+00:00] INFO: Volume vol-4842ecc4 is available
        - create a volume with id= size=16 availability_zone=us-east-1a and update the node data with created volume's id
        * aws_ebs_volume[backup_volume] action attach[2015-07-17T11:57:08+00:00] INFO: Processing aws_ebs_volume[backup_volume] action attach (my-cookbook::backupvolume line 49)
      [2015-07-17T11:57:08+00:00] DEBUG: Providers for generic aws_ebs_volume resource enabled on node include: [LWRP provider aws_ebs_volume from cookbook aws]
      [2015-07-17T11:57:08+00:00] DEBUG: Provider for action attach on resource aws_ebs_volume[backup_volume] is LWRP provider aws_ebs_volume from cookbook aws
      [2015-07-17T11:57:08+00:00] DEBUG: Attaching vol-4842ecc4 as /dev/sdi


        ================================================================================
        Error executing action `attach` on resource 'aws_ebs_volume[backup_volume]'
        ================================================================================

        Aws::EC2::Errors::InvalidInstanceIDNotFound
        -------------------------------------------
        The instance ID 'i-36a93b84' does not exist

        Cookbook Trace:
        ---------------
        /var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:212:in `attach_volume'
        /var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:70:in `block (2 levels) in class_from_file'
        /var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:68:in `block in class_from_file'

        Resource Declaration:
        ---------------------
        # In /var/chef/cache/cookbooks/my-cookbook/recipes/backupvolume.rb

         49:       aws_ebs_volume "backup_volume" do
         50:         aws_access_key aws['aws_access_key_id']
         51:         aws_secret_access_key aws['aws_secret_access_key']
         52:         size 16
         53:         device "/dev/sdi"
         54:         description "TEST BACKUP"
         55:         availability_zone "us-east-1a"
         56:         action [ :create, :attach ]
         57:       end
         58:

        Compiled Resource:
        ------------------
        # Declared in /var/chef/cache/cookbooks/my-cookbook/recipes/backupvolume.rb:49:in `from_file'

        aws_ebs_volume("backup_volume") do
          action [:create, :attach]
          updated true
          retries 0
          retry_delay 2
          default_guard_interpreter :default
          declared_type :aws_ebs_volume
          cookbook_name "my-cookbook"
          recipe_name "backupvolume"
          aws_access_key "********"
          aws_secret_access_key "********"
          size 16
          device "/dev/sdi"
          description "TEST BACKUP"
          availability_zone "us-east-1a"
          timeout 180
          volume_type "standard"
          piops 0
        end

Here is the stacktrace: 这是堆栈跟踪:

Aws::EC2::Errors::InvalidInstanceIDNotFound: aws_ebs_volume[backup_volume] (my-cookbook::backupvolume line 49) had an error: Aws::EC2::Errors::InvalidInstanceIDNotFound: The instance ID 'i-36a93b84' does not exist
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/seahorse/client/plugins/param_conversion.rb:22:in `call'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/seahorse/client/plugins/response_target.rb:18:in `call'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/seahorse/client/request.rb:70:in `send_request'
/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/aws-sdk-core-2.0.48/lib/seahorse/client/base.rb:216:in `block (2 levels) in define_operation_methods'
/var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:212:in `attach_volume'
/var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:70:in `block (2 levels) in class_from_file'
/opt/chef/embedded/apps/chef/lib/chef/mixin/why_run.rb:52:in `call'
/opt/chef/embedded/apps/chef/lib/chef/mixin/why_run.rb:52:in `add_action'
/opt/chef/embedded/apps/chef/lib/chef/provider.rb:175:in `converge_by'
/var/chef/cache/cookbooks/aws/providers/ebs_volume.rb:68:in `block in class_from_file'

The problem was due to my own foolishnes. 问题是由于我自己的愚蠢。

The AWS credentials in the databag were for an old decomissioned AWS account but the AWS credentials used to create the instance w/ knife were for the current AWS account. 数据袋中的AWS凭证用于退役的旧AWS账户,但用于创建实例(带刀)的AWS凭证用于当前的AWS账户。

Once they correct keys were put in the databag, the volume successfully created and attached! 将正确的密钥放入数据袋后,便成功创建并附加了卷!

Hope this helps someone in the future... 希望这对以后的人有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM