ruby / OSX 10.9.2:chef plugin knife-ec2安装成功,但仍然无法使用

时间:2014-03-28 17:32:20

标签: ruby chef osx-mavericks knife

我已经把头发拉了大约整整24小时了。我一直在寻找解决方案。我已经尝试了一切我能找到的东西。

我想做什么: 为'knife'程序安装ec2插件;一个非常有用的工具,可以与Chef服务器进行交互。

会发生什么 一切都回来了彩虹和独角兽。 module installed。模块不可用,也无法找到任何成功安装的证据。

我的环境: 详细信息在本文末尾。 高级别:安装了OSX 10.9.2 w / BREW以及Xcode 5.1

最简单地展示我的问题:

尝试安装gem

bash-3.2$ sudo -E gem install knife-ec2
Fetching: knife-windows-0.5.15.gem (100%)
Successfully installed knife-windows-0.5.15
Fetching: knife-ec2-0.8.0.gem (100%)
Successfully installed knife-ec2-0.8.0
Parsing documentation for knife-windows-0.5.15
Installing ri documentation for knife-windows-0.5.15
Parsing documentation for knife-ec2-0.8.0
Installing ri documentation for knife-ec2-0.8.0
2 gems installed

Fanstastic!它已经安装好了。整齐。这很简单! 哦,等等

bash-3.2$ knife ec2
FATAL: Cannot find sub command for: 'ec2'
The ec2 commands were moved to plugins in Chef 0.10
You can install the plugin with `(sudo) gem install knife-ec2

bash-3.2$ sudo knife ec2
FATAL: Cannot find sub command for: 'ec2'
The ec2 commands were moved to plugins in Chef 0.10
You can install the plugin with `(sudo) gem install knife-ec2

它不能以root或普通用户身份使用。

更多阅读之后(部分见How to install knife-ec2),我尝试了不同的方法

bash-3.2$ cd /opt/chef/embedded/bin/
bash-3.2$ sudo ./gem install knife-ec2
Building native extensions.  This could take a while...
ERROR:  Error installing knife-ec2:
    ERROR: Failed to build gem native extension.

        /opt/chef/embedded/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.1.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.1.0/libxslt/1.1.26)...
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/opt/chef/embedded/bin/ruby
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-iconv-dir
    --without-iconv-dir
    --with-iconv-include
    --without-iconv-include=${iconv-dir}/include
    --with-iconv-lib
    --without-iconv-lib=${iconv-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-pkg-config
    --without-pkg-config
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-libiconv-config
    --without-libiconv-config
    --with-pkg-config
    --without-pkg-config
/opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:983:in `block in find_header'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:982:in `find_header'
    from extconf.rb:166:in `<main>'


Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.1 for inspection.
Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out

尝试与上述相同的方法,但定期用户访问

bash-3.2$ ./gem install knife-ec2
Fetching: nokogiri-1.6.1.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /opt/chef/embedded/lib/ruby/gems/1.9.1 directory.

有关我的ruby设置的更多信息

bash-3.2$ rvm -v

rvm 1.25.22 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]


bash-3.2$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

以下是env列表。希望这对你有所帮助。

bash-3.2$ env
TERM_PROGRAM=iTerm.app
SHELL=/bin/bash
TERM=xterm
TMPDIR=/var/folders/m7/x_zjzw412rvg7rb_gz8135m5_0892r/T/
Apple_PubSub_Socket_Render=/tmp/launch-bEYnaW/Render
CDC_PREW2KHOST=<xOMITTEDx>
AWS_AVAILABILITY_REGION=us-west-1
OLDPWD=/tmp
COM_GOOGLE_CHROME_FRAMEWORK_SERVICE_PROCESS/USERS/<xOMITTEDx>/LIBRARY/APPLICATION_SUPPORT/GOOGLE/CHROME_SOCKET=/tmp/launch-KSHJfT/ServiceProcessSocket
USER=<xOMITTEDx>
AWS_AVAILABILITY_ZONE=us-west-1a
SSH_AUTH_SOCK=/tmp/launch-lUS8iG/Listeners
__CF_USER_TEXT_ENCODING=0x54042458:0:0
AWS_SSH_KEY_PAIR=<xOMITTEDx>
PATH=/Users/<xOMITTEDx>/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
__CHECKFIX1436934=1
PWD=/tmp/libxslt-1.1.28
EDITOR=/usr/bin/nano
AWS_SECRET_ACCESS_KEY=<xOMITTEDx>
LANG=en_US.UTF-8
ITERM_PROFILE=Default
USER_PRINCIPAL_NAME=<xOMITTEDx>@CORP.ACXIOM.NET
CDC_JOINED_DC=fsccorpdc01.corp.acxiom.net
AWS_ACCESS_KEY_ID=<xOMITTEDx>
HOME=/Users/<xOMITTEDx>
COLORFGBG=7;0
SHLVL=2
CDC_JOINED_SITE=<xOMITTEDx>
ITERM_SESSION_ID=w0t1p0
LOGNAME=<xOMITTEDx>
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future
CDC_JOINED_ZONE=DC=corp,DC=acxiom,DC=net
CDC_LOCALHOST=<xOMITTEDx>0214mac.corp.acxiom.net
AWS_ACCESS_KEY=<xOMITTEDx>
AWS_SECRET_KEY=<xOMITTEDx>
CDC_JOINED_DOMAIN=corp.acxiom.net
_=/usr/bin/env
bash-3.2$ sudo env
TERM=xterm
SSH_AUTH_SOCK=/tmp/launch-lUS8iG/Listeners
__CF_USER_TEXT_ENCODING=0x54042458:0:0
PATH=/Users/<xOMITTEDx>/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
EDITOR=/usr/bin/nano
LANG=en_US.UTF-8
HOME=/Users/<xOMITTEDx>
COLORFGBG=7;0
SHELL=/bin/bash
MAIL=/var/mail/root
LOGNAME=root
USER=root
USERNAME=root
SUDO_COMMAND=/usr/bin/env
SUDO_USER=<xOMITTEDx>
SUDO_UID=1409557592
SUDO_GID=20

5 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,但使用了不同的插件 这让它对我有用:

knife无法找到插件,虽然它说它会寻找gem install“ed”的插件。我认为问题是rvm部分,并且宝石安装在一个完全不同的文件夹中:

~/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/

您可以使用gem env命令

进行检查
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2012-02-16 patchlevel 125) [x86_64-darwin12.5.0]
  - INSTALLATION DIRECTORY: /Users/phil/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/phil/.rbenv/versions/1.9.3-p125/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/phil/.rbenv/versions/1.9.3-p125/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /Users/phil/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1
     - /Users/phil/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

所以我将宝石链接到我的~/.chef/plugins/knife文件夹,如下所示:

$ ln -s ~/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/knife-digital_ocean-0.7.0 ./knife-digital_ocean-0.7.0
$ ln -s ~/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/knife-solo-0.4.2 ./knife-solo-0.4.2

现在knife可以找到插件了:

$ knife digital_ocean
FATAL: Cannot find sub command for: 'digital_ocean'
Available digital_ocean subcommands: (for details, knife SUB-COMMAND --help)

** DIGITAL_OCEAN COMMANDS **
knife digital_ocean droplet create (options)
knife digital_ocean droplet destroy (options)
knife digital_ocean droplet list (options)
knife digital_ocean image list (options)
knife digital_ocean region list (options)
knife digital_ocean size list (options)
knife digital_ocean sshkey list

也适用于ec2插件...

答案 1 :(得分:3)

我安装了最新的厨师,然后运行了这个:

% sudo /opt/chefdk/embedded/bin/gem install knife-ec2



% knife ec2 server list                              
WARNING: No knife configuration file found
ERROR: You did not provide a valid 'AWS Access Key Id' value.
ERROR: You did not provide a valid 'AWS Secret Access Key' value.

这是预期的行为。设置正确的AWS凭证后,工作正常

答案 2 :(得分:0)

如果你有宝石作为sudo或明确地从/opt/chef/embedded/bin/运行它,你只是依赖于你路径中的knife

您需要确保gem命令和knife命令来自您认为来自的相同位置。

答案 3 :(得分:0)

跟进通过的人)

在安装gem之前,您可能只需要libxml标头:

$ yum -y install libxml2-devel # or apt-get install libxml2-dev
$ which knife
/usr/bin/knife
$ ls -l /usr/bin/knife
0 lrwxrwxrwx 1 root root 21 Jun  6 06:39 /usr/bin/knife -> /opt/chefdk/bin/knife
$ head -1 /opt/chefdk/bin/knife 
#!/opt/chefdk/embedded/bin/ruby
$ sudo /opt/chefdk/embedded/bin/gem install knife-ec2 --no-rdoc --no-ri

答案 4 :(得分:-1)

解决方案是使用虚拟盒并安装一个简单的ubuntu映像。