From 47973378ef5ae1b4d42655e4917e0edfc05edfb9 Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Tue, 3 Mar 2015 11:32:09 +0100 Subject: [PATCH] Update module-data to 0eead7f411f404b0a9a73bb161aac46c9fbe3219 0eead7f411f404b0a9a73bb161aac46c9fbe3219 Merge pull request #22 from droyo/master 1a8a82433401086db667f88e825f77dcff2f6d66 Support the override parameter of the hiera functions. 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 | 33 +++++++++++-------- module-data/metadata.json | 10 ++++++ 5 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 module-data/.gitignore create mode 100644 module-data/metadata.json diff --git a/Puppetfile b/Puppetfile index fb6ead5d7..a37dea083 100644 --- a/Puppetfile +++ b/Puppetfile @@ -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', 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..94cd72ccb 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,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)) @@ -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 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": [] +}