Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) provisioning lists of images from a file #78

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions lib/puppet_litmus/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ def run_local_command(command)
end
end

desc "provision list of machines from provision.yaml file. 'bundle exec rake 'litmus:provision_list[default]'"
task :provision_list, [:key] do |_task, args|
provision_hash = YAML.load_file('./provision.yaml')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some bikeshedding: perhaps litmus.yaml? Also feels like this should be configurable - perhaps an env var with a default?

provisioner = provision_hash[args[:key]]['provisioner']
provision_hash[args[:key]]['images'].each do |image|
include PuppetLitmus
Rake::Task['spec_prep'].invoke
config_data = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') }
raise "the provision module was not found in #{config_data['modulepath']}, please amend the .fixtures.yml file" unless File.directory?(File.join(config_data['modulepath'], 'provision'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated in various tasks. It'd be good to at least add a helper for this.


params = { 'action' => 'provision', 'platform' => image, 'inventory' => Dir.pwd }
results = run_task("provision::#{provisioner}", 'localhost', params, config: config_data, inventory: nil)
results.each do |result|
if result['status'] != 'success'
puts "Failed on #{result['node']}\n#{result}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be on stderr?

else
puts "Provisioned #{result['result']['node_name']}"
end
end
end
end

desc "provision container/VM - abs/docker/vmpooler eg 'bundle exec rake 'litmus:provision[vmpooler, ubuntu-1604-x86_64]'"
task :provision, [:provisioner, :platform] do |_task, args|
include PuppetLitmus
Expand Down Expand Up @@ -173,15 +195,12 @@ def run_local_command(command)
run_local_command("bundle exec bolt file upload #{module_tar} /tmp/#{File.basename(module_tar)} --nodes #{target_string} --inventoryfile inventory.yaml")
install_module_command = "puppet module install /tmp/#{File.basename(module_tar)}"
result = run_command(install_module_command, target_nodes, config: nil, inventory: inventory_hash)
# rubocop:disable Style/GuardClause
if result.is_a?(Array)
result.each do |node|
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
end
else
raise "Failed trying to run '#{install_module_command}' against inventory."
raise "Failed trying to run '#{install_module_command}' against inventory." unless result.is_a?(Array)

result.each do |node|
puts "#{node['node']} failed #{node['result']}" if node['status'] != 'success'
end
# rubocop:enable Style/GuardClause

puts 'Installed'
end

Expand Down