forked from attachmentgenie/vagrant-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
36 lines (31 loc) · 1.01 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env rake
# encoding: utf-8
require 'yaml'
vagrant_root = File.expand_path(File.dirname(__FILE__))
if File.file?(vagrant_root + '/vagrant.yaml')
vagrant_config = YAML.load_file(vagrant_root + '/vagrant.yaml')
elsif File.file?(vagrant_root + '/vagrant.yaml.dist')
vagrant_config = YAML.load_file(vagrant_root + '/vagrant.yaml.dist')
else
raise "No vagrant config is provided."
end
task default: %w[inspec]
task :inspec, [:node] do |t, args|
if args[:node]
nodes = [{'name' => args[:node]}]
elsif vagrant_config['nodes']
nodes = vagrant_config['nodes']
else
raise "Node definitions are missing."
end
nodes.each do |node|
name = node["name"]
puts
if(File.directory?("test/#{name}"))
puts "Profile found for node #{name}"
sh("bundle exec inspec exec test/#{name} --sudo -t ssh://[email protected]:$(vagrant port --guest 22 #{name}) -i #{vagrant_root}/.vagrant/machines/#{name}/virtualbox/private_key")
else
puts "No profile found for node #{name}"
end
end
end