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

Update to Bolt inventory v2 #12

Merged
merged 2 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Gemfile.local
/site-modules
*.box
*.rerun.json
.resource_types
8 changes: 0 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: true
ExcludedMethods:
- initialize
- finalize!
- validate
- to_proc
Max: 25
Metrics/ClassLength:
Enabled: false
Metrics/ModuleLength:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ matrix:
fast_finish: true
include:
- rvm: 2.4.4
env: TEST_VAGRANT_VERSION=v2.2.2
env: TEST_VAGRANT_VERSION=v2.2.7
- rvm: 2.5.0
env: TEST_VAGRANT_VERSION=HEAD
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
require 'rubygems/version'

vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.2.2'
vagrant_branch = ENV['TEST_VAGRANT_VERSION'] || 'v2.2.7'

group :plugins do
gemspec
Expand Down Expand Up @@ -31,7 +31,7 @@ group :test do
end

group :system_tests do
gem 'bolt', ">=1.5.0"
gem 'bolt', "~> 1.48.0"
end


Expand Down
18 changes: 9 additions & 9 deletions acceptance/components/bolt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt task run 'facts'})
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt plan run 'facts'})
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run})
expect(@result.stdout.scan(%r{Successful on 1 node}).size).to eq(3)
expect(@result.stdout.scan(%r{Successful on 1 target}).size).to eq(3)
end
end

Expand All @@ -39,7 +39,7 @@
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt task run 'facts'})
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt plan run 'facts'})
expect(@result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run})
expect(@result.stdout.scan(%r{Successful on 1 node}).size).to eq(3)
expect(@result.stdout.scan(%r{Successful on 1 target}).size).to eq(3)
end
end

Expand All @@ -50,18 +50,18 @@

it 'runs a task, plan, and command' do
expect(@result.exit_code).to eq(0)
result = assert_execute('vagrant', 'bolt', 'task', 'run', 'facts', '-n', 'server')
result = assert_execute('vagrant', 'bolt', 'task', 'run', 'facts', '-t', 'server')
expect(result.exit_code).to eq(0)
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'task' 'run' 'facts'})
expect(result.stdout.scan(%r{Successful on 1 node}).size).to eq(1)
result = assert_execute('vagrant', 'bolt', 'plan', 'run', 'facts', '-n', 'server')
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
result = assert_execute('vagrant', 'bolt', 'plan', 'run', 'facts', '-t', 'server')
expect(result.exit_code).to eq(0)
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'plan' 'run' 'facts'})
expect(result.stdout.scan(%r{Successful on 1 node}).size).to eq(1)
result = assert_execute('vagrant', 'bolt', 'command', 'run', 'hostname', '-n', 'server')
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
result = assert_execute('vagrant', 'bolt', 'command', 'run', 'hostname', '-t', 'server')
expect(result.exit_code).to eq(0)
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: '\/[^\ ]+bolt' 'command' 'run'})
expect(result.stdout.scan(%r{Successful on 1 node}).size).to eq(1)
expect(result.stdout.scan(%r{Successful on 1 target}).size).to eq(1)
end
end

Expand All @@ -86,7 +86,7 @@
# Ensure that the root level `run_as` is used
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+allnodetest[^\n]+--run-as 'root'})
## Configtest
# Ensure excludes overrides nodes
# Ensure excludes overrides targets
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+configtest[^\n]+server2})
# Ensure verbose and debug flags are correctly handled
expect(result.stdout).to match(%r{Bolt: Running bolt command locally: \/[^\ ]+bolt command run[^\n]+configtest[^\n]+--verbose})
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bolt/config_builder/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def eval_bolt_triggers(config)

def eval_bolt_triggers_root(vm_root_config)
# Configure the vm bolt object if the options exist
triggers = attr(:bolt_triggers) || [] # rubocop:disable Style/Attr
triggers = attr(:bolt_triggers) || []
triggers.each do |config|
f = VagrantBolt::ConfigBuilder::Triggers.new_from_hash(config)
f.call(vm_root_config)
Expand Down
8 changes: 4 additions & 4 deletions lib/vagrant-bolt/util/bolt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.generate_bolt_command(config, inventory_path = nil)
end

command << "--inventoryfile \'#{inventory_path}\'" unless inventory_path.nil?
command << "--nodes \'#{config.node_list}\'" unless config.node_list.nil?
command << "--targets \'#{config.node_list}\'" unless config.node_list.nil?
command << config.args unless config.args.nil?
command.flatten.join(" ")
end
Expand All @@ -45,12 +45,12 @@ def self.generate_bolt_command(config, inventory_path = nil)
# @param env [Object] The env object
# @return [Hash] The hash of config options for the inventory.yaml
def self.generate_inventory_hash(env)
inventory = { 'nodes' => [] }
inventory = { 'version' => 2, 'targets' => [] }
inventory.merge!(env.vagrantfile.config.bolt.inventory_config.compact)
VagrantBolt::Util::Machine.nodes_in_environment(env).each do |vm|
next unless VagrantBolt::Util::Machine.running?(vm)

inventory['nodes'] << generate_node_hash(vm)
inventory['targets'] << generate_node_hash(vm)
end
inventory.compact
end
Expand All @@ -70,7 +70,7 @@ def self.generate_node_hash(machine)
transport = VagrantBolt::Util::Machine.windows?(machine) ? 'winrm' : 'ssh'
node_hash['config'][transport] = machine_transport_hash(machine, machine_config, ssh_info).compact
node_hash['config']['transport'] = transport
node_hash['name'] = "#{transport}://#{ssh_info[:host]}:#{node_hash['config'][transport]['port']}"
node_hash['uri'] = "#{transport}://#{ssh_info[:host]}:#{node_hash['config'][transport]['port']}"
machine_config.each do |key, value|
next if key == 'config' || value.nil? || value.empty?

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bolt/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module VagrantBolt
VERSION = '0.1.3'
VERSION = '0.2.0'
end
2 changes: 1 addition & 1 deletion spec/unit/runner/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
config.boltdir = '.'
config.node_list = 'ssh://test:22'
config.finalize!
command = "bolt task run 'foo' --boltdir '.' --inventoryfile '#{inventory_path}' --nodes 'ssh://test:22'"
command = "bolt task run 'foo' --boltdir '.' --inventoryfile '#{inventory_path}' --targets 'ssh://test:22'"
expect(Vagrant::Util::Subprocess).to receive(:execute).with('bash', '-c', command, options).and_return(subprocess_result)
subject.run('task', 'foo')
end
Expand Down
7 changes: 4 additions & 3 deletions spec/unit/util/bolt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"transport" => "ssh",
},
"name" => "ssh://machine:22",
"uri" => "ssh://machine:22",
"facts" => { 'a' => 'b' },
"vars" => { 'foo' => 'bar' },
"features" => ['foo'],
Expand All @@ -48,8 +48,9 @@
let(:config_hash) { { 'config' => { 'a' => 'b' } } }
let(:node_hash) do
{
'nodes' => [machine_hash],
'targets' => [machine_hash],
'config' => config_hash['config'],
'version' => 2,
}
end
before(:each) do
Expand Down Expand Up @@ -95,7 +96,7 @@
config.node_list = 'ssh://test:22'
config.user = 'user'
config.finalize!
expected = "bolt task run 'foo' --user \'user\' --inventoryfile '#{inventory_path}' --nodes \'ssh://test:22\'"
expected = "bolt task run 'foo' --user \'user\' --inventoryfile '#{inventory_path}' --targets \'ssh://test:22\'"
expect(subject.generate_bolt_command(config, inventory_path)).to eq(expected)
end

Expand Down