首页 > 解决方案 > 运行 exec 时出现 inspec-aws 错误

问题描述

知道我做错了什么我安装了chefworkstation:

$ chef -v
Chef Workstation version: 21.4.365
Chef Infra Client version: 16.12.3
Chef InSpec version: 4.29.3
Chef CLI version: 4.0.0
Chef Habitat version: 1.6.288
Test Kitchen version: 2.11.2
Cookstyle version: 7.10.0

aws cli 已安装,我已经设置了一个正常工作的默认凭据(通过部署一些 tf 代码确认)

创建一个文件夹并运行

inspec init profile --platform aws tftest

安装 aws-sdk for 2.7.3 (Using rbenv) 并捆绑安装 sdk

宝石文件

source 'https://rubygems.org/' do
    gem 'aws-sdk', '~> 3'
end

然后我运行:

inspec exec tftest -t aws://

并得到以下错误:

$ inspec exec tftest -t aws://
Traceback (most recent call last):
        30: from /usr/bin/inspec:354:in `<main>'
        29: from /usr/bin/inspec:354:in `load'
        28: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-bin-4.29.3/bin/inspec:11:in `<top (required)>'
        27: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/base_cli.rb:35:in `start'
        26: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
        25: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
        24: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
        23: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
        22: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/cli.rb:281:in `exec'
        21: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/runner.rb:135:in `run'
        20: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/runner.rb:101:in `load'
        19: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/runner.rb:101:in `each'
        18: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/runner.rb:107:in `block in load'
        17: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile.rb:259:in `load_libraries'
        16: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile.rb:259:in `each_with_index'
        15: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile.rb:259:in `each'
        14: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile.rb:278:in `block in load_libraries'
        13: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile.rb:285:in `load_libraries'
        12: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:143:in `load_libraries'
        11: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:143:in `each'
        10: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:144:in `block in load_libraries'
         9: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:159:in `load_library_file'
         8: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:170:in `load_with_context'
         7: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/profile_context.rb:170:in `instance_eval'
         6: from libraries/aws_alb.rb:3:in `load_with_context'
         5: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/dsl_shared.rb:47:in `require'
         4: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/dsl_shared.rb:47:in `eval'
         3: from libraries/aws_backend.rb:13:in `create'
         2: from /opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.29.3/lib/inspec/dsl_shared.rb:33:in `require'
         1: from /opt/chef-workstation/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- aws-sdk-ecrpublic (LoadError)

我尝试更新我的 Gemfile 以包含 gem 'aws-sdk-ecrpublic' 但我仍然收到相同的错误

文件夹布局为:

.
├── Gemfile
├── Gemfile.lock
├── README.md
├── .ruby-version
└── tftest
    ├── controls
    │   └── example.rb
    ├── inspec.lock
    ├── inspec.yml
    └── README.md

知道有什么问题吗?

标签: rubyamazon-web-servicesinspec

解决方案


这是对这个问题的一个非常晚的答案,但是 inspec-aws 依赖于需要安装的 train-aws。https://github.com/inspec/train-aws


推荐阅读