From bfdeb9a8a4daed99de099d431048c87acb99c06f Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Tue, 2 Dec 2014 18:11:28 +0100 Subject: [PATCH] Update module-data to 010c9eb3496f515582a4d4868154e5fb246ee9b8 010c9eb3496f515582a4d4868154e5fb246ee9b8 Merge pull request #20 from radford/add-dependencies-to-metadata 161bbda59d0c3d685b75dfafa38214f437658252 puppet considers metadata without dependencies to be invalid aaa06fd0549da48b01616bcb875796ef18fdf359 Merge pull request #19 from fatmcgav/fix_issue_18 7b776609b6661d204c31e08600070c0737466aa4 Convert Modulefile to metadata.json. d0065f5a7d5cf54a98ab93cf4fe8afc3449d5b7c Fixes issue #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 #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 #12 from bobtfish/master fa48b9a677b699efaa1cd9a97258026a08444e97 Fix to work with strict_variables = true 8c0c106b908fe3808165a2e8775b5b341522b4a8 Merge pull request #11 from jolynch/master 6127ac5eedcc8a8c55ecf9b9a6ed80b8d1a0bc52 Use the global scope for environment lookup --- Puppetfile | 2 +- module-data/.gitignore | 1 + module-data/Modulefile | 2 +- .../lib/hiera/backend/module_data_backend.rb | 32 +++++++++++-------- module-data/metadata.json | 10 ++++++ 5 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 module-data/.gitignore create mode 100644 module-data/metadata.json diff --git a/Puppetfile b/Puppetfile index 03873332b..3d79d9218 100644 --- a/Puppetfile +++ b/Puppetfile @@ -67,7 +67,7 @@ mod 'memcached', :git => 'https://github.com/saz/puppet-memcached.git' mod 'module-data', - :commit => '159fc5e0e21ce9df96c777f0064b5eca88e29cae', + :commit => '010c9eb3496f515582a4d4868154e5fb246ee9b8', :git => 'https://github.com/ripienaar/puppet-module-data.git' mod 'mongodb', diff --git a/module-data/.gitignore b/module-data/.gitignore new file mode 100644 index 000000000..d8fe4fa70 --- /dev/null +++ b/module-data/.gitignore @@ -0,0 +1 @@ +/.project diff --git a/module-data/Modulefile b/module-data/Modulefile index 5c05ad258..976df9ccb 100644 --- a/module-data/Modulefile +++ b/module-data/Modulefile @@ -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' diff --git a/module-data/lib/hiera/backend/module_data_backend.rb b/module-data/lib/hiera/backend/module_data_backend.rb index 5e8ff3a37..a865bb8cf 100644 --- a/module-data/lib/hiera/backend/module_data_backend.rb +++ b/module-data/lib/hiera/backend/module_data_backend.rb @@ -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 = {} @@ -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) @@ -44,15 +44,19 @@ 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 @@ -67,19 +71,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 diff --git a/module-data/metadata.json b/module-data/metadata.json new file mode 100644 index 000000000..44df666d8 --- /dev/null +++ b/module-data/metadata.json @@ -0,0 +1,10 @@ +{ + "author": "R.I.Pienaar ", + "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": [] +}