vagrant-chefconfig 0.0.2 → 0.1.0
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/Gemfile +1 -1
- data/README.md +40 -9
- data/Rakefile +3 -1
- data/Vagrantfile +1 -1
- data/lib/vagrant-chefconfig/chef_client_configurator.rb +36 -23
- data/lib/vagrant-chefconfig/knife_config.rb +28 -0
- data/lib/vagrant-chefconfig/knife_config_locator.rb +73 -0
- data/lib/vagrant-chefconfig/path_helper.rb +27 -0
- data/lib/vagrant-chefconfig/version.rb +1 -1
- data/vagrant-chefconfig.gemspec +1 -2
- metadata +19 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f509a14e5ea7178235cdbe28f7f5795532e4155b
|
4
|
+
data.tar.gz: d33cdfa17892f30c543554d46b0c177acb05bd95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f953660d958c572f1b79ebfbb0ec3d2b4d9226f797530a3356e90ebd063dc4263510038d6cead17fa597b9f7ff522cca619042e1d36b501529806543e42bc6
|
7
|
+
data.tar.gz: f249315e7323e2bd3dd99a805f3f6de46b72ecabf015f5db6b798b8716bc01d253bb4b8df487d7b204b488f284d86366a887bb0d41ba041bc3f2fcd8895c32ab
|
data/Gemfile
CHANGED
@@ -7,7 +7,7 @@ group :development do
|
|
7
7
|
# We depend on Vagrant for development, but we don't add it as a
|
8
8
|
# gem dependency because we expect to be installed within the
|
9
9
|
# Vagrant environment itself using `vagrant plugin`.
|
10
|
-
gem "vagrant", :
|
10
|
+
gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git"
|
11
11
|
end
|
12
12
|
|
13
13
|
# This group is read by Vagrant for plugin development
|
data/README.md
CHANGED
@@ -21,14 +21,33 @@ end
|
|
21
21
|
|
22
22
|
The plugin will automatically configure the following Vagrant chef-client provisioner attributes from your knife.rb.
|
23
23
|
|
24
|
-
Vagrant chef-client attribute -> knife config attribute
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
## Vagrant chef-client attribute -> knife config attribute
|
25
|
+
<table>
|
26
|
+
<tr>
|
27
|
+
<th>Vagrant attribute name</th>
|
28
|
+
<th>Knife attribute name</th>
|
29
|
+
</tr>
|
30
|
+
<tr>
|
31
|
+
<td>chef_server_url</td>
|
32
|
+
<td>chef_server_url</td>
|
33
|
+
</tr>
|
34
|
+
<tr>
|
35
|
+
<td>log_level</td>
|
36
|
+
<td>log_level</td>
|
37
|
+
</tr>
|
38
|
+
<tr>
|
39
|
+
<td>validation_key_path</td>
|
40
|
+
<td>validation_key</td>
|
41
|
+
</tr>
|
42
|
+
<tr>
|
43
|
+
<td>environment</td>
|
44
|
+
<td>vagrant_environment</td>
|
45
|
+
</tr>
|
46
|
+
<tr>
|
47
|
+
<td>encrypted_data_bag_secret_key_path</td>
|
48
|
+
<td>encrypted_data_bag_secret</td>
|
49
|
+
</tr>
|
50
|
+
</table>
|
32
51
|
|
33
52
|
Values specified directly in the Vagrantfile override any configured values found in your knife configuration file.
|
34
53
|
|
@@ -41,14 +60,26 @@ By default the plugin will be enabled and the path to the knife.rb uses the [sta
|
|
41
60
|
|
42
61
|
## Changelog
|
43
62
|
|
63
|
+
### 0.1.0
|
64
|
+
|
65
|
+
- Added support for Vagrant 1.7+.
|
66
|
+
- Fixed issue 1. Don't read knife.rb if there are no chef-client provisioner blocks in Vagrantfile.
|
67
|
+
- Removed dependency upon Chef gem. Handles loading Knife config directly with mixlib-config
|
68
|
+
|
44
69
|
### 0.0.1
|
45
70
|
|
46
|
-
Initial release for Vagrant 1.5
|
71
|
+
- Initial release for Vagrant 1.5
|
47
72
|
|
48
73
|
# Authors
|
49
74
|
|
50
75
|
* Shawn Neal (<sneal@sneal.net>)
|
51
76
|
|
77
|
+
## Developing
|
78
|
+
|
79
|
+
1. Clone repo
|
80
|
+
2. `bundle install`
|
81
|
+
3. `bundle exec vagrant up`
|
82
|
+
|
52
83
|
## Contributing
|
53
84
|
|
54
85
|
1. Fork it
|
data/Rakefile
CHANGED
data/Vagrantfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# vi: set ft=ruby :
|
3
3
|
|
4
4
|
Vagrant.configure('2') do |config|
|
5
|
-
config.vm.box =
|
5
|
+
config.vm.box = 'chef/ubuntu-14.04'
|
6
6
|
config.vm.provision :chef_client do |chef|
|
7
7
|
chef.node_name = 'vagrant_chefconfig_test_vm'
|
8
8
|
chef.run_list = [ 'apt' ]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'log4r'
|
2
|
-
|
3
|
-
|
2
|
+
require_relative 'knife_config'
|
3
|
+
require_relative 'knife_config_locator'
|
4
4
|
|
5
5
|
module Vagrant
|
6
6
|
module ChefConfig
|
@@ -12,16 +12,20 @@ module Vagrant
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def apply_knife_config()
|
15
|
+
provisioners = chef_client_provisioners
|
16
|
+
return if provisioners.length == 0
|
17
|
+
|
15
18
|
load_knife_config()
|
16
19
|
|
17
|
-
|
18
|
-
chef_config =
|
20
|
+
provisioners.each do |provisioner|
|
21
|
+
chef_config = provisioner.config
|
19
22
|
|
20
|
-
|
21
|
-
set_if_default(chef_config, :
|
22
|
-
set_if_default(chef_config, :
|
23
|
-
set_if_default(chef_config, :
|
24
|
-
set_if_default(chef_config, :
|
23
|
+
# vagrant config key knife config key
|
24
|
+
set_if_default(chef_config, :chef_server_url, :chef_server_url)
|
25
|
+
set_if_default(chef_config, :log_level, :log_level)
|
26
|
+
set_if_default(chef_config, :validation_key_path, :validation_key)
|
27
|
+
set_if_default(chef_config, :validation_client_name, :validation_client_name)
|
28
|
+
set_if_default(chef_config, :environment, :vagrant_environment)
|
25
29
|
set_if_default(chef_config, :encrypted_data_bag_secret_key_path, :encrypted_data_bag_secret)
|
26
30
|
end
|
27
31
|
end
|
@@ -29,45 +33,54 @@ module Vagrant
|
|
29
33
|
|
30
34
|
private
|
31
35
|
|
32
|
-
def set_if_default(chef_config, config_prop_sym,
|
36
|
+
def set_if_default(chef_config, config_prop_sym, knife_prop_sym)
|
33
37
|
config_val = chef_config.send(config_prop_sym)
|
38
|
+
knife_val = KnifeConfig[knife_prop_sym]
|
34
39
|
|
35
40
|
@logger.debug("Vagrantfile config val #{config_prop_sym} = #{config_val}")
|
36
|
-
@logger.debug("Knife config val #{
|
41
|
+
@logger.debug("Knife config val #{knife_prop_sym} = #{knife_val}")
|
37
42
|
|
38
|
-
if
|
43
|
+
if is_default_vagrant_value(config_prop_sym, config_val)
|
39
44
|
@logger.debug("Overwriting '#{config_prop_sym}' in Vagrantfile chef-client " +
|
40
|
-
"provisioner with '#{
|
41
|
-
chef_config.send("#{config_prop_sym}=",
|
45
|
+
"provisioner with '#{knife_val}'")
|
46
|
+
chef_config.send("#{config_prop_sym}=", knife_val)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
45
|
-
def
|
50
|
+
def is_default_vagrant_value(config_prop_sym, config_val)
|
46
51
|
case config_prop_sym
|
47
52
|
when :validation_client_name
|
48
53
|
return config_val == 'chef-validator'
|
49
|
-
when :
|
50
|
-
return config_val ==
|
54
|
+
when :log_level
|
55
|
+
return config_val == :info
|
51
56
|
else
|
52
57
|
return config_val.nil?
|
53
58
|
end
|
54
59
|
end
|
55
60
|
|
56
61
|
def chef_client_provisioners()
|
57
|
-
@env[:machine].config.vm.provisioners.select
|
62
|
+
@env[:machine].config.vm.provisioners.select do |prov|
|
63
|
+
begin
|
64
|
+
prov.type == :chef_client
|
65
|
+
rescue NoMethodError
|
66
|
+
prov.name == :chef_client # support for Vagrant <= 1.6.5
|
67
|
+
end
|
68
|
+
end
|
58
69
|
end
|
59
70
|
|
60
71
|
def load_knife_config()
|
61
72
|
knife_config_path = locate_knife_config_file()
|
62
73
|
@logger.debug("Using knife config from '#{knife_config_path}'")
|
63
|
-
|
74
|
+
KnifeConfig.from_file(knife_config_path)
|
64
75
|
end
|
65
76
|
|
66
77
|
def locate_knife_config_file()
|
67
|
-
# If the Vagrantfile directly sets the knife.rb path use it, otherwise
|
68
|
-
#
|
78
|
+
# If the Vagrantfile directly sets the knife.rb path use it, otherwise
|
79
|
+
# default to the .chef directory under the user's home dir
|
80
|
+
# This could be improved to have the same behavior as Chef for finding
|
81
|
+
# the knife.rb relative to the current directory
|
69
82
|
knife_config_path = plugin_config().knife_config_path
|
70
|
-
knife_config_path ? knife_config_path :
|
83
|
+
knife_config_path ? knife_config_path : KnifeConfigLocator.new().locate_local_config
|
71
84
|
end
|
72
85
|
|
73
86
|
def plugin_config()
|
@@ -76,4 +89,4 @@ module Vagrant
|
|
76
89
|
|
77
90
|
end #ChefClientConfigurator
|
78
91
|
end
|
79
|
-
end
|
92
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mixlib/config'
|
2
|
+
require_relative 'path_helper'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
module ChefConfig
|
6
|
+
# Subset of Chef Config class functionality
|
7
|
+
# Matches Chef 12 default behavior
|
8
|
+
class KnifeConfig
|
9
|
+
|
10
|
+
extend Mixlib::Config
|
11
|
+
|
12
|
+
default :chef_server_url, "https://localhost:443"
|
13
|
+
default :log_level, :auto
|
14
|
+
default(:validation_key) { PathHelper.platform_specific_path("/etc/chef/validation.pem") }
|
15
|
+
default :validation_client_name, 'chef-validator'
|
16
|
+
default :vagrant_environment, :dev
|
17
|
+
|
18
|
+
default(:encrypted_data_bag_secret) do
|
19
|
+
key_path = PathHelper.platform_specific_path("/etc/chef/encrypted_data_bag_secret")
|
20
|
+
if File.exist?(key_path)
|
21
|
+
key_path
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative 'path_helper'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module ChefConfig
|
5
|
+
# Locates the local knife config using the same behavior as Chef 12
|
6
|
+
# Borrowed from Chef WorkstationConfigLoader
|
7
|
+
# Author:: Daniel DeLeo (<dan@getchef.com>)
|
8
|
+
class KnifeConfigLocator
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@logger = Log4r::Logger.new("vagrant_chefconfig::knifeconfiglocator")
|
12
|
+
end
|
13
|
+
|
14
|
+
def locate_local_config
|
15
|
+
candidate_configs = []
|
16
|
+
|
17
|
+
# Look for $KNIFE_HOME/knife.rb (allow multiple knives config on same machine)
|
18
|
+
if ENV['KNIFE_HOME']
|
19
|
+
candidate_configs << File.join(ENV['KNIFE_HOME'], 'config.rb')
|
20
|
+
candidate_configs << File.join(ENV['KNIFE_HOME'], 'knife.rb')
|
21
|
+
end
|
22
|
+
# Look for $PWD/knife.rb
|
23
|
+
if Dir.pwd
|
24
|
+
candidate_configs << File.join(Dir.pwd, 'config.rb')
|
25
|
+
candidate_configs << File.join(Dir.pwd, 'knife.rb')
|
26
|
+
end
|
27
|
+
# Look for $UPWARD/.chef/knife.rb
|
28
|
+
if chef_config_dir
|
29
|
+
candidate_configs << File.join(chef_config_dir, 'config.rb')
|
30
|
+
candidate_configs << File.join(chef_config_dir, 'knife.rb')
|
31
|
+
end
|
32
|
+
# Look for $HOME/.chef/knife.rb
|
33
|
+
candidate_configs << File.join(home_dot_chef_dir, 'config.rb')
|
34
|
+
candidate_configs << File.join(home_dot_chef_dir, 'knife.rb')
|
35
|
+
|
36
|
+
candidate_configs.find do | candidate_config |
|
37
|
+
have_config?(candidate_config)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def chef_config_dir
|
44
|
+
if @chef_config_dir.nil?
|
45
|
+
@chef_config_dir = false
|
46
|
+
full_path = Dir.pwd.split(File::SEPARATOR)
|
47
|
+
(full_path.length - 1).downto(0) do |i|
|
48
|
+
candidate_directory = File.join(full_path[0..i] + [".chef" ])
|
49
|
+
if File.exist?(candidate_directory) && File.directory?(candidate_directory)
|
50
|
+
@chef_config_dir = candidate_directory
|
51
|
+
break
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
@chef_config_dir
|
56
|
+
end
|
57
|
+
|
58
|
+
def home_dot_chef_dir
|
59
|
+
File.join(Dir.home, '.chef')
|
60
|
+
end
|
61
|
+
|
62
|
+
def have_config?(path)
|
63
|
+
if File.exist?(path)
|
64
|
+
@logger.info("Using config at #{path}")
|
65
|
+
true
|
66
|
+
else
|
67
|
+
@logger.debug("Config not found at #{path}, trying next option")
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module ChefConfig
|
3
|
+
# Helper to deal with paths, mainly on Windows
|
4
|
+
# Borrowed from Chef 12 PathHelper class
|
5
|
+
class PathHelper
|
6
|
+
def self.platform_specific_path(path)
|
7
|
+
path = cleanpath(path)
|
8
|
+
if Gem.win_platform?
|
9
|
+
# \etc\chef\client.rb and \var\chef\client.rb -> C:/chef/client.rb
|
10
|
+
if env['SYSTEMDRIVE'] && path[0] == '\\' && path.split('\\')[2] == 'chef'
|
11
|
+
path = File.join(env['SYSTEMDRIVE'], path.split('\\', 3)[2])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
path
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.cleanpath(path)
|
18
|
+
path = Pathname.new(path).cleanpath.to_s
|
19
|
+
# ensure all forward slashes are backslashes
|
20
|
+
if Gem.win_platform?
|
21
|
+
path = path.gsub(File::SEPARATOR, path_separator)
|
22
|
+
end
|
23
|
+
path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/vagrant-chefconfig.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.
|
21
|
+
gem.add_runtime_dependency "mixlib-config", "~> 2"
|
22
22
|
|
23
23
|
gem.add_development_dependency "rake"
|
24
24
|
gem.add_development_dependency "rspec"
|
25
|
-
gem.add_development_dependency "bundler", ">= 1.3"
|
26
25
|
end
|
metadata
CHANGED
@@ -1,71 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-chefconfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Neal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: mixlib-config
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bundler
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.3'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.3'
|
69
55
|
description: Load Chef gem client config from knife.rb
|
70
56
|
email:
|
71
57
|
- sneal@sneal.net
|
@@ -73,8 +59,8 @@ executables: []
|
|
73
59
|
extensions: []
|
74
60
|
extra_rdoc_files: []
|
75
61
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
78
64
|
- Gemfile
|
79
65
|
- LICENSE.txt
|
80
66
|
- README.md
|
@@ -87,6 +73,9 @@ files:
|
|
87
73
|
- lib/vagrant-chefconfig/config.rb
|
88
74
|
- lib/vagrant-chefconfig/env.rb
|
89
75
|
- lib/vagrant-chefconfig/errors.rb
|
76
|
+
- lib/vagrant-chefconfig/knife_config.rb
|
77
|
+
- lib/vagrant-chefconfig/knife_config_locator.rb
|
78
|
+
- lib/vagrant-chefconfig/path_helper.rb
|
90
79
|
- lib/vagrant-chefconfig/plugin.rb
|
91
80
|
- lib/vagrant-chefconfig/version.rb
|
92
81
|
- vagrant-chefconfig.gemspec
|
@@ -100,17 +89,17 @@ require_paths:
|
|
100
89
|
- lib
|
101
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
91
|
requirements:
|
103
|
-
- -
|
92
|
+
- - ">="
|
104
93
|
- !ruby/object:Gem::Version
|
105
94
|
version: '0'
|
106
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
96
|
requirements:
|
108
|
-
- -
|
97
|
+
- - ">="
|
109
98
|
- !ruby/object:Gem::Version
|
110
99
|
version: '0'
|
111
100
|
requirements: []
|
112
101
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.2.2
|
114
103
|
signing_key:
|
115
104
|
specification_version: 4
|
116
105
|
summary: Duplicating Chef client configuration is less than ideal, lets reuse our
|