我使用Terraform在基于AWS EC2的对接主机上自动构建,然后使用它的远程exec选项下载一个坞文件,构建并运行它。
我本来希望把它与Serverspec结合起来,但我很难解决两件事:
我通常会使用预定义的密钥对连接到EC2实例,并且从不使用密码,但是ServerSpec似乎以sudo -p格式在服务器上运行命令。
任何建议都很感激。
spec_helper.rb含量
require 'serverspec'
require 'net/ssh'
set :ssh_options, :user => 'ec2-user'还使用以下编辑的rakefile强制正确的EC2外部dns (掩码):
require 'rake'
require 'rspec/core/rake_task'
hosts = %w(
ec2-nn-nn-nn-nnn.eu-west-1.compute.amazonaws.com
)
set :ssh_options, :user => 'ec2-user'
task :spec => 'spec:all'
namespace :spec do
task :all => hosts.map {|h| 'spec:' + h.split('.')[0] }
hosts.each do |host|
short_name = host.split('.')[0]
role = short_name.match(/[^0-9]+/)[0]
desc "Run serverspec to #{host}"
RSpec::Core::RakeTask.new(short_name) do |t|
ENV['TARGET_HOST'] = host
t.pattern = "spec/Nexus/*_spec.rb"
end
end
end发布于 2016-06-16 02:33:18
web:
输出“地址”{ value = "${aws_instance.web.public_dns}“}
然后,您可以在terraform apply和terraform output address之后从命令行获得这个值。https://stackoverflow.com/questions/37844113
复制相似问题