vagrant-ansible_auto 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +5 -4
- data/Rakefile +17 -2
- data/Vagrantfile +1 -0
- data/lib/vagrant/ansible_auto/command/inventory.rb +9 -8
- data/lib/vagrant/ansible_auto/command/root.rb +8 -8
- data/lib/vagrant/ansible_auto/inventory.rb +1 -1
- data/lib/vagrant/ansible_auto/plugin.rb +12 -3
- data/lib/vagrant/ansible_auto/version.rb +1 -1
- data/locales/en.yml +9 -3
- data/spec/acceptance/cli/inventory_spec.rb +77 -0
- data/spec/acceptance/cli/root_spec.rb +40 -0
- data/spec/acceptance/output/inventory_output.rb +23 -0
- data/spec/acceptance/output/root_output.rb +23 -0
- data/spec/acceptance/support-skeletons/cli/ansible-inventory/Vagrantfile +45 -0
- data/spec/acceptance/support-skeletons/cli/ansible-inventory/playbook.yml +0 -0
- data/spec/spec_helper.rb +19 -2
- data/spec/support/{context.rb → unit/context.rb} +6 -0
- data/spec/support/{matchers.rb → unit/matchers.rb} +0 -0
- data/spec/unit/vagrant/ansible_auto/config_spec.rb +4 -5
- data/spec/unit/vagrant/ansible_auto/inventory_spec.rb +2 -2
- data/vagrant-spec.config.rb +13 -2
- metadata +11 -5
- data/Vagrantfile +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86bbf45cb65b33f971d3877a02f1290ff18a8424
|
4
|
+
data.tar.gz: 482b76a61c9dd6259936b188c4581bfdca21cf75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ece562c557c5a437ecd86d24f424c482de6f4106f18bc20709a8451901bff83c4bbd79a3f762c388799d6197ea3b9f8bbfa649386b91e0a2756cae292f7b1e0
|
7
|
+
data.tar.gz: '08e522fb58ea6f9347270e46cd0a973aad935c909e31d33efdd926858c98bc7cb6e3c349e68c67d037016dd68dbdbdc78fd03408dacdba3db9c86283b0accc6b'
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,15 @@ IMPROVEMENTS:
|
|
6
6
|
|
7
7
|
BUG FIXES:
|
8
8
|
|
9
|
+
## 0.2.2 (August 23, 2017)
|
10
|
+
|
11
|
+
BUG FIXES:
|
12
|
+
|
13
|
+
- `vagrant ansible inventory --help` no longer prints an inventory after the
|
14
|
+
help text
|
15
|
+
- `vagrant ansible --help` shows available subcommands rather than an `I18n`
|
16
|
+
"translation missing" error message
|
17
|
+
|
9
18
|
## 0.2.1 (July 29, 2017)
|
10
19
|
|
11
20
|
BUG FIXES:
|
data/Gemfile
CHANGED
@@ -5,7 +5,9 @@ source 'https://rubygems.org'
|
|
5
5
|
group :development do
|
6
6
|
gem 'pry'
|
7
7
|
gem 'vagrant', github: 'mitchellh/vagrant'
|
8
|
-
|
8
|
+
# Lock to commit just before update to rspec ~> 3.5.0, which broke the whole
|
9
|
+
# dang thing :(
|
10
|
+
gem 'vagrant-spec', github: 'mitchellh/vagrant-spec', ref: '2f0fb10'
|
9
11
|
end
|
10
12
|
|
11
13
|
group :plugins do
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
GIT
|
2
2
|
remote: git://github.com/mitchellh/vagrant-spec.git
|
3
3
|
revision: 2f0fb10862b2d19861c584be9d728080ba1f5d33
|
4
|
+
ref: 2f0fb10
|
4
5
|
specs:
|
5
6
|
vagrant-spec (0.0.1)
|
6
7
|
childprocess (~> 0.6.0)
|
@@ -10,7 +11,7 @@ GIT
|
|
10
11
|
|
11
12
|
GIT
|
12
13
|
remote: git://github.com/mitchellh/vagrant.git
|
13
|
-
revision:
|
14
|
+
revision: dce71a5a27c93d97c9262e7562c0fd5abfc2fd9a
|
14
15
|
specs:
|
15
16
|
vagrant (1.9.8.dev)
|
16
17
|
childprocess (~> 0.6.0)
|
@@ -33,7 +34,7 @@ GIT
|
|
33
34
|
PATH
|
34
35
|
remote: .
|
35
36
|
specs:
|
36
|
-
vagrant-ansible_auto (0.2.
|
37
|
+
vagrant-ansible_auto (0.2.2)
|
37
38
|
|
38
39
|
GEM
|
39
40
|
remote: https://rubygems.org/
|
@@ -120,11 +121,11 @@ GEM
|
|
120
121
|
ruby_dep (1.3.1)
|
121
122
|
rubyntlm (0.6.2)
|
122
123
|
rubyzip (1.2.1)
|
123
|
-
simplecov (0.
|
124
|
+
simplecov (0.15.0)
|
124
125
|
docile (~> 1.1.0)
|
125
126
|
json (>= 1.8, < 3)
|
126
127
|
simplecov-html (~> 0.10.0)
|
127
|
-
simplecov-html (0.10.
|
128
|
+
simplecov-html (0.10.2)
|
128
129
|
slop (3.6.0)
|
129
130
|
term-ansicolor (1.2.2)
|
130
131
|
tins (~> 0.8)
|
data/Rakefile
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
|
5
5
|
require 'rspec/core/rake_task'
|
6
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
RSpec::Core::RakeTask.new(:spec).tap do |rspec_task|
|
7
|
+
rspec_task.pattern = './spec/unit{,/*/**}/*_spec.rb'
|
8
|
+
end
|
7
9
|
|
8
10
|
require 'rubocop/rake_task'
|
9
11
|
RuboCop::RakeTask.new
|
@@ -11,4 +13,17 @@ RuboCop::RakeTask.new
|
|
11
13
|
require 'yard'
|
12
14
|
YARD::Rake::YardocTask.new
|
13
15
|
|
14
|
-
|
16
|
+
desc 'Run vagrant-spec'
|
17
|
+
namespace 'vagrant-spec' do
|
18
|
+
desc 'Output vagrant-spec components'
|
19
|
+
task :components do
|
20
|
+
sh('vagrant-spec', 'components')
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Run vagrant-spec tests'
|
24
|
+
task :test do
|
25
|
+
sh('vagrant-spec', 'test', '--components=cli/ansible-inventory')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: %i[rubocop spec vagrant-spec:test]
|
data/Vagrantfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./spec/acceptance/support-skeletons/cli/ansible-inventory/Vagrantfile
|
@@ -9,7 +9,7 @@ module VagrantPlugins
|
|
9
9
|
class Inventory < Vagrant.plugin(2, :command)
|
10
10
|
# @return [String] summary of the +ansible inventory+ command
|
11
11
|
def self.synopsis
|
12
|
-
'
|
12
|
+
I18n.t('vagrant.ansible_auto.command.inventory.synopsis')
|
13
13
|
end
|
14
14
|
|
15
15
|
# Print the Ansible inventory for the current Vagrantfile.
|
@@ -23,26 +23,26 @@ module VagrantPlugins
|
|
23
23
|
operation = :as_ini
|
24
24
|
|
25
25
|
opts = OptionParser.new do |op|
|
26
|
-
op.banner = '
|
26
|
+
op.banner = I18n.t('vagrant.ansible_auto.command.inventory.usage')
|
27
27
|
op.separator ''
|
28
|
-
op.separator '
|
28
|
+
op.separator I18n.t('vagrant.ansible_auto.command.inventory.available_options')
|
29
29
|
|
30
|
-
op.on('--ini',
|
30
|
+
op.on('--ini', I18n.t('vagrant.ansible_auto.command.inventory.option.ini')) do
|
31
31
|
operation = :as_ini
|
32
32
|
end
|
33
33
|
|
34
|
-
op.on('--json', '
|
34
|
+
op.on('--json', I18n.t('vagrant.ansible_auto.command.inventory.option.json')) do
|
35
35
|
operation = :as_json
|
36
36
|
end
|
37
37
|
|
38
|
-
op.on('--pretty', '
|
38
|
+
op.on('--pretty', I18n.t('vagrant.ansible_auto.command.inventory.option.pretty')) do
|
39
39
|
operation = :as_pretty_json
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
machines = parse_options(opts)
|
44
44
|
|
45
|
-
@env.ui.info send(operation, machines), prefix: false
|
45
|
+
@env.ui.info send(operation, machines), prefix: false unless machines.nil?
|
46
46
|
|
47
47
|
0
|
48
48
|
end
|
@@ -64,8 +64,9 @@ module VagrantPlugins
|
|
64
64
|
def build_inventory(machines)
|
65
65
|
with_target_vms(machines) {}.each_with_object(AnsibleAuto::Inventory.new) do |machine, inventory|
|
66
66
|
unless machine.state.id == :running
|
67
|
-
@env.ui.warn
|
67
|
+
@env.ui.warn I18n.t('vagrant.ansible_auto.command.inventory.diag.not_running', machine_name: machine.name), channel: :error
|
68
68
|
end
|
69
|
+
|
69
70
|
inventory.merge!(machine.config.ansible.inventory)
|
70
71
|
inventory.add_host(machine)
|
71
72
|
end
|
@@ -13,7 +13,7 @@ module VagrantPlugins
|
|
13
13
|
class Root < Vagrant.plugin(2, :command)
|
14
14
|
# @return [String] summary of the +ansible+ command
|
15
15
|
def self.synopsis
|
16
|
-
'
|
16
|
+
I18n.t('vagrant.ansible_auto.command.root.synopsis')
|
17
17
|
end
|
18
18
|
|
19
19
|
# Execute the +ansible+ command
|
@@ -34,17 +34,17 @@ module VagrantPlugins
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def prepare_options
|
37
|
-
OptionParser.new do |
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
OptionParser.new do |op|
|
38
|
+
op.banner = I18n.t('vagrant.ansible_auto.command.root.usage')
|
39
|
+
op.separator ''
|
40
|
+
op.separator I18n.t('vagrant.ansible_auto.command.root.available_subcommands')
|
41
41
|
|
42
42
|
subcommands.keys.sort.each do |k|
|
43
|
-
|
43
|
+
op.separator " #{k}"
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
op.separator ''
|
47
|
+
op.separator I18n.t('vagrant.ansible_auto.command.root.subcommand_help')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -144,7 +144,7 @@ module VagrantPlugins
|
|
144
144
|
# @param [Array] members the hosts to add to the group
|
145
145
|
# @return [Set] the members of the added group
|
146
146
|
def add_group(group, *members)
|
147
|
-
raise InvalidGroupNameError, group: group if group.to_s == UNNAMED_GROUP
|
147
|
+
raise Errors::InvalidGroupNameError, group: group if group.to_s == UNNAMED_GROUP
|
148
148
|
|
149
149
|
add_complex_group(group, members.pop) if members.last.is_a? Hash
|
150
150
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
load 'vagrant/ansible_auto.rb'
|
4
|
+
|
3
5
|
# Namespace for Vagrant plugins
|
4
6
|
module VagrantPlugins
|
5
7
|
# Namespace for the +ansible_auto+ provisioner and +ansible+ command
|
@@ -13,6 +15,15 @@ module VagrantPlugins
|
|
13
15
|
on guest machines
|
14
16
|
DESC
|
15
17
|
|
18
|
+
def self.init!
|
19
|
+
require 'i18n'
|
20
|
+
|
21
|
+
VagrantPlugins::AnsibleAuto.source_root.join('locales/en.yml').tap do |en|
|
22
|
+
I18n.load_path << en unless I18n.load_path.include? en
|
23
|
+
I18n.reload!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
16
27
|
config 'ansible' do
|
17
28
|
require_relative 'config'
|
18
29
|
Config
|
@@ -80,9 +91,7 @@ module VagrantPlugins
|
|
80
91
|
end
|
81
92
|
|
82
93
|
action_hook 'environment_plugins_loaded' do
|
83
|
-
|
84
|
-
I18n.load_path << VagrantPlugins::AnsibleAuto.source_root.join('locales/en.yml')
|
85
|
-
I18n.reload!
|
94
|
+
init!
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
data/locales/en.yml
CHANGED
@@ -15,15 +15,21 @@ en:
|
|
15
15
|
command:
|
16
16
|
root:
|
17
17
|
synopsis: 'build an Ansible inventory'
|
18
|
+
usage: 'Usage: vagrant ansible <subcommand> [<args>]'
|
19
|
+
available_subcommands: 'Available subcommands:'
|
20
|
+
subcommand_help: 'For help on any individual subcommand run `vagrant ansible SUBCOMMAND -h`'
|
18
21
|
option: {}
|
19
22
|
diag: {}
|
20
|
-
|
23
|
+
inventory:
|
21
24
|
synopsis: 'output a dynamic Ansible inventory'
|
22
25
|
usage: 'Usage: vagrant ansible inventory [options]'
|
26
|
+
available_options: 'Available options:'
|
23
27
|
option:
|
24
|
-
|
28
|
+
ini: 'List all hosts as INI'
|
29
|
+
json: 'List all hosts as terse JSON'
|
30
|
+
pretty: 'List all hosts as pretty JSON'
|
25
31
|
diag:
|
26
|
-
not_running: 'machine %{
|
32
|
+
not_running: 'machine %{machine_name} is not running; falling back to default hostvar values'
|
27
33
|
errors:
|
28
34
|
inventory:
|
29
35
|
missing_group: 'expected group %{group} is missing from the inventory'
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'vagrant/ansible_auto'
|
6
|
+
|
7
|
+
describe 'CLI: ansible inventory', component: 'cli/ansible-inventory' do
|
8
|
+
include_context 'acceptance'
|
9
|
+
|
10
|
+
def execute_ansible_inventory(*args)
|
11
|
+
execute('vagrant', 'ansible', 'inventory', *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_execute_ansible_inventory(*args)
|
15
|
+
assert_execute('vagrant', 'ansible', 'inventory', *args)
|
16
|
+
end
|
17
|
+
|
18
|
+
around do |ex|
|
19
|
+
begin
|
20
|
+
saved_env = ENV.to_h
|
21
|
+
ENV['VAGRANT_CWD'] = environment.workdir.to_s
|
22
|
+
environment.skeleton('cli/ansible-inventory')
|
23
|
+
ex.run
|
24
|
+
ensure
|
25
|
+
ENV.replace(saved_env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'given the --ini option' do
|
30
|
+
it 'returns the inventory as INI' do
|
31
|
+
result = assert_execute_ansible_inventory('--ini')
|
32
|
+
[
|
33
|
+
/^ansible-test-control\s+/,
|
34
|
+
/^ansible-test-worker-1\s+/,
|
35
|
+
/^ansible-test-worker-2\s+/,
|
36
|
+
/^\[control\]\s*$/,
|
37
|
+
/^\[worker\]\s*$/
|
38
|
+
].each do |regex|
|
39
|
+
expect(result.stdout).to match regex
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'given the --json option' do
|
45
|
+
it 'returns the inventory as terse JSON' do
|
46
|
+
result = assert_execute_ansible_inventory('--json')
|
47
|
+
expect(result.stdout.lines.count).to be == 1
|
48
|
+
expect { JSON.parse(result.stdout.strip) }.not_to raise_error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'given the --pretty option' do
|
53
|
+
it 'returns the inventory as pretty JSON' do
|
54
|
+
result = assert_execute_ansible_inventory('--pretty')
|
55
|
+
expect(result.stdout.lines.count).to be > 1
|
56
|
+
expect { JSON.parse(result.stdout.strip) }.not_to raise_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'given the --help option' do
|
61
|
+
let!(:help_output) { assert_execute_ansible_inventory('--help').stdout }
|
62
|
+
|
63
|
+
it 'prints a usage message' do
|
64
|
+
expect(help_output).to match_output(:inventory_usage)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'prints an available options stanza' do
|
68
|
+
expect(help_output).to match_output(:inventory_available_options)
|
69
|
+
end
|
70
|
+
|
71
|
+
%w[ini json pretty].each do |type|
|
72
|
+
it "prints a usage message for the --#{type} option" do
|
73
|
+
expect(help_output).to match_output(:"inventory_option_#{type}")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vagrant/ansible_auto'
|
4
|
+
|
5
|
+
describe 'CLI: ansible', component: 'cli/ansible' do
|
6
|
+
include_context 'acceptance'
|
7
|
+
|
8
|
+
around do |ex|
|
9
|
+
begin
|
10
|
+
saved_env = ENV.to_h
|
11
|
+
ENV['VAGRANT_CWD'] = environment.workdir.to_s
|
12
|
+
environment.skeleton('cli/ansible-inventory')
|
13
|
+
ex.run
|
14
|
+
ensure
|
15
|
+
ENV.replace(saved_env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'given the --help option' do
|
20
|
+
let!(:help_output) { assert_execute('vagrant', 'ansible', '--help').stdout }
|
21
|
+
|
22
|
+
it 'prints a usage message' do
|
23
|
+
expect(help_output).to match_output(:root_usage)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'prints an available subcommands stanza' do
|
27
|
+
expect(help_output).to match_output(:root_available_subcommands)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'indicates where to get help on subcommand usage' do
|
31
|
+
expect(help_output).to match_output(:root_subcommand_help)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'given the list-commands vagrant command' do
|
36
|
+
it 'displays a synopsis' do
|
37
|
+
expect(assert_execute('vagrant', 'list-commands').stdout).to match_output(:root_synopsis)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vagrant-spec/acceptance/output'
|
4
|
+
|
5
|
+
require 'vagrant/ansible_auto/command/inventory'
|
6
|
+
require 'vagrant/ansible_auto/errors'
|
7
|
+
require 'vagrant/ansible_auto/plugin'
|
8
|
+
|
9
|
+
VagrantPlugins::AnsibleAuto::Plugin.init!
|
10
|
+
|
11
|
+
module Vagrant
|
12
|
+
module Spec
|
13
|
+
OutputTester[:bad_extension] = lambda do |text|
|
14
|
+
text =~ Regexp.new(Regexp.escape(VagrantPlugins::AnsibleAuto::Errors::BadExtensionError.new.message))
|
15
|
+
end
|
16
|
+
|
17
|
+
%w[synopsis usage available_options option.ini option.json option.pretty diag.not_running].each do |trk|
|
18
|
+
OutputTester[:"inventory_#{trk.tr('.', '_')}"] = lambda do |text|
|
19
|
+
text =~ Regexp.new(Regexp.escape(I18n.t("vagrant.ansible_auto.command.inventory.#{trk}")))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vagrant-spec/acceptance/output'
|
4
|
+
|
5
|
+
require 'vagrant/ansible_auto/command/root'
|
6
|
+
require 'vagrant/ansible_auto/errors'
|
7
|
+
require 'vagrant/ansible_auto/plugin'
|
8
|
+
|
9
|
+
VagrantPlugins::AnsibleAuto::Plugin.init!
|
10
|
+
|
11
|
+
module Vagrant
|
12
|
+
module Spec
|
13
|
+
OutputTester[:bad_extension] = lambda do |text|
|
14
|
+
text =~ Regexp.new(Regexp.escape(VagrantPlugins::AnsibleAuto::Errors::BadExtensionError.new.message))
|
15
|
+
end
|
16
|
+
|
17
|
+
%w[synopsis usage available_subcommands subcommand_help].each do |trk|
|
18
|
+
OutputTester[:"root_#{trk.tr('.', '_')}"] = lambda do |text|
|
19
|
+
text =~ Regexp.new(Regexp.escape(I18n.t("vagrant.ansible_auto.command.root.#{trk}")))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Vagrant.configure(2) do |config|
|
2
|
+
config.vm.box = 'hashicorp/precise64'
|
3
|
+
|
4
|
+
(1..2).each do |i|
|
5
|
+
name = "ansible-test-worker-#{i}"
|
6
|
+
|
7
|
+
config.vm.define name do |machine|
|
8
|
+
machine.vm.provider :docker do |d|
|
9
|
+
d.image = 'baxterstockman/minideb-vagrant'
|
10
|
+
d.has_ssh = true
|
11
|
+
end
|
12
|
+
|
13
|
+
machine.ansible.groups = {
|
14
|
+
'worker' => name,
|
15
|
+
'cluster:children' => ['worker']
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.vm.define 'ansible-test-control' do |machine|
|
21
|
+
machine.vm.provider :docker do |d|
|
22
|
+
d.image = 'baxterstockman/minideb-vagrant'
|
23
|
+
d.has_ssh = true
|
24
|
+
end
|
25
|
+
|
26
|
+
machine.vm.provision :ansible_auto do |ansible|
|
27
|
+
ansible.limit = '*'
|
28
|
+
ansible.playbook = 'playbooks/test.yml'
|
29
|
+
end
|
30
|
+
|
31
|
+
machine.ansible.groups = {
|
32
|
+
'control' => ['ansible-test-control'],
|
33
|
+
'cluster:children' => ['control']
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
config.ansible.vars = {
|
38
|
+
'control' => {
|
39
|
+
'role' => 'ansible-control'
|
40
|
+
},
|
41
|
+
'worker' => {
|
42
|
+
'role' => 'ansible-worker'
|
43
|
+
}
|
44
|
+
}
|
45
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -2,12 +2,29 @@
|
|
2
2
|
|
3
3
|
require 'pathname'
|
4
4
|
|
5
|
+
type = if File.basename($PROGRAM_NAME) == 'vagrant-spec'
|
6
|
+
'acceptance'
|
7
|
+
else
|
8
|
+
'unit'
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.pattern = "#{type}/**/*_spec.rb"
|
13
|
+
config.color = true
|
14
|
+
config.formatter = 'documentation'
|
15
|
+
config.order = 'rand'
|
16
|
+
end
|
17
|
+
|
5
18
|
Pathname.new(__FILE__).tap do |helper|
|
6
19
|
$LOAD_PATH.unshift((helper.parent.parent + 'lib').to_s)
|
7
20
|
|
8
21
|
require 'vagrant/ansible_auto'
|
9
22
|
|
10
|
-
helper.parent.join('support').
|
23
|
+
if (support_dir = helper.parent.join('support', type)).directory?
|
24
|
+
support_dir.find { |f| require f if f.extname == '.rb' }
|
25
|
+
end
|
11
26
|
end
|
12
27
|
|
13
|
-
|
28
|
+
if type == 'unit'
|
29
|
+
SimpleCov.start unless SimpleCov.running
|
30
|
+
end
|
@@ -72,6 +72,12 @@ shared_context 'machine' do |machine_count = 2|
|
|
72
72
|
let(:ui) { machine.ui }
|
73
73
|
let(:communicator) { machine.communicator }
|
74
74
|
let(:playbook) { 'playbook.yml' }
|
75
|
+
|
76
|
+
before do |example|
|
77
|
+
# Ensure that we always create the Vagrant::Environment, unless explicitly
|
78
|
+
# told not to
|
79
|
+
iso_env unless example.metadata.fetch(:skip_create_vagrant_env) { false }
|
80
|
+
end
|
75
81
|
end
|
76
82
|
|
77
83
|
shared_context 'host' do
|
File without changes
|
@@ -39,11 +39,10 @@ describe VagrantPlugins::AnsibleAuto::Config do
|
|
39
39
|
|
40
40
|
context 'given an error constructing the inventory' do
|
41
41
|
it 'catches the error and returns it under the "ansible_auto" key' do
|
42
|
-
pending 'at the moment, the inventory object does not raise any errors along the relevant code paths'
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
42
|
+
pending 'at the moment, the inventory object does not raise any errors along the relevant code paths'
|
43
|
+
config.finalize!
|
44
|
+
errors = config.validate(machine)
|
45
|
+
expect(errors['ansible_auto']).not_to be_empty
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
@@ -50,7 +50,7 @@ describe VagrantPlugins::AnsibleAuto::Inventory do
|
|
50
50
|
|
51
51
|
inventory.vars.tap do |vars|
|
52
52
|
expect(vars).to have_key('mygroup')
|
53
|
-
expect(vars['mygroup']).to include(this
|
53
|
+
expect(vars['mygroup']).to include('this' => 'n', 'uh' => 'that', 'n' => 'uh')
|
54
54
|
end
|
55
55
|
|
56
56
|
inventory.children.tap do |children|
|
@@ -62,7 +62,7 @@ describe VagrantPlugins::AnsibleAuto::Inventory do
|
|
62
62
|
context 'given an invalid group name' do
|
63
63
|
it 'raises an error' do
|
64
64
|
expect { inventory.add_group('_') }.to raise_error do |error|
|
65
|
-
expect(error).to be_a(VagrantPlugins::AnsibleAuto::InvalidGroupNameError)
|
65
|
+
expect(error).to be_a(VagrantPlugins::AnsibleAuto::Errors::InvalidGroupNameError)
|
66
66
|
expect(error.message).to match(/_ is not a valid group name/)
|
67
67
|
end
|
68
68
|
end
|
data/vagrant-spec.config.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Vagrant::Spec::Acceptance.configure do |config|
|
4
|
+
config.component_paths << 'spec/acceptance'
|
5
|
+
config.skeleton_paths << 'spec/acceptance/support-skeletons'
|
6
|
+
|
7
|
+
# Silence Vagrant's "You appear to be running Vagrant outside of the official
|
8
|
+
# installers" message. This message mucks up things like parsing the output
|
9
|
+
# of `vagrant-skel` with JSON.load.
|
10
|
+
config.env.merge!('VAGRANT_I_KNOW_WHAT_IM_DOING_PLEASE_BE_QUIET' => '1')
|
3
11
|
end
|
12
|
+
|
13
|
+
# Pull in SimpleCov, Coveralls, and RSpec setup
|
14
|
+
require_relative 'spec/spec_helper'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-ansible_auto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Galindo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -161,9 +161,15 @@ files:
|
|
161
161
|
- lib/vagrant/ansible_auto/version.rb
|
162
162
|
- locales/en.yml
|
163
163
|
- playbooks/test.yml
|
164
|
+
- spec/acceptance/cli/inventory_spec.rb
|
165
|
+
- spec/acceptance/cli/root_spec.rb
|
166
|
+
- spec/acceptance/output/inventory_output.rb
|
167
|
+
- spec/acceptance/output/root_output.rb
|
168
|
+
- spec/acceptance/support-skeletons/cli/ansible-inventory/Vagrantfile
|
169
|
+
- spec/acceptance/support-skeletons/cli/ansible-inventory/playbook.yml
|
164
170
|
- spec/spec_helper.rb
|
165
|
-
- spec/support/context.rb
|
166
|
-
- spec/support/matchers.rb
|
171
|
+
- spec/support/unit/context.rb
|
172
|
+
- spec/support/unit/matchers.rb
|
167
173
|
- spec/unit/vagrant/ansible_auto/config_spec.rb
|
168
174
|
- spec/unit/vagrant/ansible_auto/host_spec.rb
|
169
175
|
- spec/unit/vagrant/ansible_auto/inventory_spec.rb
|
@@ -193,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
199
|
version: '0'
|
194
200
|
requirements: []
|
195
201
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.6.11
|
197
203
|
signing_key:
|
198
204
|
specification_version: 4
|
199
205
|
summary: Vagrant plugin for building ansible inventory files.
|
data/Vagrantfile
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
Vagrant.configure(2) do |config|
|
2
|
-
config.vm.box = 'hashicorp/precise64'
|
3
|
-
|
4
|
-
(1..2).each do |i|
|
5
|
-
name = "ansible-test-worker-#{i}"
|
6
|
-
|
7
|
-
config.vm.define name do |machine|
|
8
|
-
machine.vm.provider :docker do |d|
|
9
|
-
d.image = 'baxterstockman/minideb-vagrant'
|
10
|
-
d.has_ssh = true
|
11
|
-
end
|
12
|
-
|
13
|
-
machine.ansible.groups = {
|
14
|
-
'worker' => name,
|
15
|
-
'cluster:children' => ['worker']
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
config.vm.define 'ansible-test-control' do |machine|
|
21
|
-
machine.vm.provider :docker do |d|
|
22
|
-
d.image = 'baxterstockman/minideb-vagrant'
|
23
|
-
d.has_ssh = true
|
24
|
-
end
|
25
|
-
|
26
|
-
machine.vm.provision :ansible_auto do |ansible|
|
27
|
-
ansible.limit = '*'
|
28
|
-
ansible.playbook = 'playbooks/test.yml'
|
29
|
-
end
|
30
|
-
|
31
|
-
machine.ansible.groups = {
|
32
|
-
'control' => ['ansible-test-control'],
|
33
|
-
'cluster:children' => ['control']
|
34
|
-
}
|
35
|
-
end
|
36
|
-
|
37
|
-
config.ansible.vars = {
|
38
|
-
'control' => {
|
39
|
-
'role' => 'ansible-control'
|
40
|
-
},
|
41
|
-
'worker' => {
|
42
|
-
'role' => 'ansible-worker'
|
43
|
-
}
|
44
|
-
}
|
45
|
-
end
|