我有一个实例,我想在启动时运行用户脚本。所以我将此代码放在userdata中:
Content-Type: multipart/mixed; boundary="===============zCWTbYbXsHmnlc1kxsQr93CA=="
MIME-Version: 1.0
--===============zCWTbYbXsHmnlc1kxsQr93CA==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"
output: { all: '|tee -a /var/log/cloud-init-output.log' }
--===============zCWTbYbXsHmnlc1kxsQr93CA==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="zz_bootstrap.rb"
#!/usr/bin/ruby
require 'rubygems'
require 'json'
system "sudo gem install aws-sdk"
require 'aws-sdk'
r53=nil
Retrier.new(3,1).run do
r53 = AWS::Route53.new( :access_key_id => creds["AccessKeyId"],
:secret_access_key => creds["SecretAccessKey"],
:region => region)
end
Some_ruby_stuff_that_needs_r53
但是在日志中我得到了这个:
Successfully installed mini_portile-0.6.2
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.6.2
Successfully installed aws-sdk-v1-1.61.0
Successfully installed aws-sdk-1.61.0
Parsing documentation for aws-sdk-1.61.0
Installing ri documentation for aws-sdk-1.61.0
Parsing documentation for aws-sdk-v1-1.61.0
Installing ri documentation for aws-sdk-v1-1.61.0
Parsing documentation for mini_portile-0.6.2
Installing ri documentation for mini_portile-0.6.2
Parsing documentation for nokogiri-1.6.6.2
Installing ri documentation for nokogiri-1.6.6.2
Done installing documentation for aws-sdk, aws-sdk-v1, mini_portile, nokogiri after 55 seconds
4 gems installed
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- aws-sdk (LoadError)
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /var/lib/cloud/instance/scripts/zz_bootstrap.rb:8:in `<main>'
2015-01-27 13:49:46,859 - util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/zz_bootstrap.rb [1]
2015-01-27 13:49:46,875 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
2015-01-27 13:49:46,875 - util.py[WARNING]: Running scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 0.7.5 finished at Tue, 27 Jan 2015 13:49:47 +0000. Datasource DataSourceEc2. Up 389.95 seconds
所以我决定在userdata范围之外检查:
gilz@AAAA:~$ which ruby
/usr/bin/ruby
gilz@AAAA:~$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux-gnu]
gilz@AAAA:~$ gem list
*** LOCAL GEMS ***
aws-sdk (1.61.0)
aws-sdk-v1 (1.61.0)
bigdecimal (1.2.4)
celluloid (0.15.2)
celluloid-io (0.15.0)
eye (0.6.3)
io-console (0.4.2)
json (1.8.1)
mini_portile (0.6.2)
minitest (4.7.5)
nio4r (1.0.1)
nokogiri (1.6.6.2)
psych (2.0.5)
rake (10.1.0)
rdoc (4.1.0)
sigar (0.7.3)
state_machine (1.2.0)
test-unit (2.1.5.0)
thor (0.19.1)
timers (1.1.0)
所以即使我打电话给#34; sudo gem install&#34;从脚本中,它以错误的ruby版本安装gem。这没有RVM。我不关心这个运行的ruby版本(> 1.93),我只需要使用aws-sdk gem。想法?
谢谢!
答案 0 :(得分:0)
在初步阶段安装解决了这个问题:
Content-Type: multipart/mixed; boundary="===============zCWTbYbXsHmnlc1kxsQr93CA=="
MIME-Version: 1.0
--===============zCWTbYbXsHmnlc1kxsQr93CA==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config"
<强> RUNCMD: - “sudo gem install aws-sdk”
output: { all: '|tee -a /var/log/cloud-init-output.log' }
--===============zCWTbYbXsHmnlc1kxsQr93CA==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="zz_bootstrap.rb"