Skip to content

Commit

Permalink
Update module-data to 0eead7f411f404b0a9a73bb161aac46c9fbe3219
Browse files Browse the repository at this point in the history
0eead7f411f404b0a9a73bb161aac46c9fbe3219 Merge pull request redhat-openstack#22 from droyo/master
1a8a82433401086db667f88e825f77dcff2f6d66 Support the override parameter of the hiera functions.
010c9eb3496f515582a4d4868154e5fb246ee9b8 Merge pull request redhat-openstack#20 from radford/add-dependencies-to-metadata
161bbda59d0c3d685b75dfafa38214f437658252 puppet considers metadata without dependencies to be invalid
aaa06fd0549da48b01616bcb875796ef18fdf359 Merge pull request redhat-openstack#19 from fatmcgav/fix_issue_18
7b776609b6661d204c31e08600070c0737466aa4 Convert Modulefile to metadata.json.
d0065f5a7d5cf54a98ab93cf4fe8afc3449d5b7c Fixes issue redhat-openstack#18 which was resulting in a 'Can't convert nil to Hash' error when using Hash datatypes.
46f86f2384ce7914506924aab4baf2c5414cf022 release 0.0.4
7e639b87d0ce787326edf3a0c017b305e8abdd8f Merge pull request redhat-openstack#13 from telamonian/master
c9396c4332a5dc7c4df028abdfb9d4b846452f73 added .gitignore
a6729666b6b4efeb476a01125005567f2233f6c0 fixed code style
9008bfa7eded663dc08b4def9f10c415d138efd0 removed some extra Hiera.debug() lines I had put in
b9eccd31f949bd740afa2df05f44688acbcac996 Fixed hash behavior for hiera data in modules. Setting :merge_behavior to deeper works correctly now.
82ed78d5c8eba9e35697be61233b0f4aae2f6640 Merge pull request redhat-openstack#12 from bobtfish/master
fa48b9a677b699efaa1cd9a97258026a08444e97 Fix to work with strict_variables = true
8c0c106b908fe3808165a2e8775b5b341522b4a8 Merge pull request redhat-openstack#11 from jolynch/master
6127ac5eedcc8a8c55ecf9b9a6ed80b8d1a0bc52 Use the global scope for environment lookup
  • Loading branch information
xbezdick committed Mar 3, 2015
1 parent 3ae9d06 commit 4797337
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Puppetfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod 'module-collectd',
:git => 'https://github.com/pdxcat/puppet-module-collectd.git'

mod 'module-data',
:commit => '159fc5e0e21ce9df96c777f0064b5eca88e29cae',
:commit => '0eead7f411f404b0a9a73bb161aac46c9fbe3219',
:git => 'https://github.com/ripienaar/puppet-module-data.git'

mod 'mongodb',
Expand Down
1 change: 1 addition & 0 deletions module-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.project
2 changes: 1 addition & 1 deletion module-data/Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'ripienaar-module_data'
version '0.0.3'
version '0.0.4'
description 'A hiera backend to allow the use of data while writing sharable modules'
project_page 'https://github.com/ripienaar/puppet-module-data'
license 'ASL 2.0'
Expand Down
33 changes: 19 additions & 14 deletions module-data/lib/hiera/backend/module_data_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def load_module_config(module_name, environment)
default_config = {:hierarchy => ["common"]}

mod = Puppet::Module.find(module_name, environment)

return default_config unless mod

path = mod.path
module_config = File.join(path, "data", "hiera.yaml")
config = {}
Expand All @@ -25,7 +25,7 @@ def load_module_config(module_name, environment)
Hiera.debug("Reading config from %s file" % module_config)
config = load_data(module_config)
end

config["path"] = path

default_config.merge(config)
Expand All @@ -44,18 +44,23 @@ def lookup(key, scope, order_override, resolution_type)

Hiera.debug("Looking up %s in Module Data backend" % key)

unless scope["module_name"]
module_name = begin
scope["module_name"]
rescue Puppet::ParseError # Gets thrown if not in a module and strict_variables = true
end

unless module_name
Hiera.debug("Skipping Module Data backend as this does not look like a module")
return answer
end

config = load_module_config(scope["module_name"], scope["environment"])

config = load_module_config(scope["module_name"], scope["::environment"])
unless config["path"]
Hiera.debug("Could not find a path to the module '%s' in environment '%s'" % [scope["module_name"], scope["environment"]])
Hiera.debug("Could not find a path to the module '%s' in environment '%s'" % [scope["module_name"], scope["::environment"]])
return answer
end

config[:hierarchy].insert(0, order_override) if order_override
config[:hierarchy].each do |source|
source = File.join(config["path"], "data", "%s.yaml" % Backend.parse_string(source, scope))

Expand All @@ -67,19 +72,19 @@ def lookup(key, scope, order_override, resolution_type)
next if data.empty?
next unless data.include?(key)

found = data[key]

new_answer = Backend.parse_answer(data[key], scope)
case resolution_type
when :array
raise("Hiera type mismatch: expected Array or String and got %s" % found.class) unless [Array, String].include?(found.class)
raise("Hiera type mismatch: expected Array and got %s" % new_answer.class) unless (new_answer.kind_of?(Array) || new_answer.kind_of?(String))
answer ||= []
answer << Backend.parse_answer(found, scope)
answer << new_answer

when :hash
raise("Hiera type mismatch: expected Hash and got %s" % found.class) unless found.is_a?(Hash)
answer = Backend.parse_answer(found, scope).merge(answer || {})
raise("Hiera type mismatch: expected Hash and got %s" % new_answer.class) unless new_answer.kind_of?(Hash)
answer ||= {}
answer = Backend.merge_answer(new_answer, answer)
else
answer = Backend.parse_answer(found, scope)
answer = new_answer
break
end
end
Expand Down
10 changes: 10 additions & 0 deletions module-data/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"author": "R.I.Pienaar <[email protected]>",
"license": "ASL 2.0",
"name": "ripienaar-module_data",
"project_page": "https://github.com/ripienaar/puppet-module-data",
"source": "https://github.com/ripienaar/puppet-module-data.git",
"summary": "A hiera backend to allow the use of data while writing sharable modules",
"version": "0.4.0",
"dependencies": []
}

0 comments on commit 4797337

Please sign in to comment.