Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify params_lookup() to be able to search module::varname #92

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
language: ruby
rvm:
- 1.8.7
- 1.9.3
script:
- "bundle exec rake lint spec SPEC_OPTS='--format documentation'"
matrix:
Expand All @@ -14,6 +16,7 @@ matrix:
- rvm: 2.1.4
# env: STRICT_VARIABLES="yes"

gemfile: .gemfile
notifications:
email:
- [email protected]
11 changes: 11 additions & 0 deletions lib/puppet/parser/functions/params_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#
# This function lookups for a variable value in various locations
# following this order (first match is returned)
# - Hiera backend (if present) for modulename::varname
# - Hiera backend (if present) for modulename_varname
# - Hiera backend (if present) for varname (if second argument is 'global')
# - Top Scope Variable ::modulename::varname
# - Top Scope Variable ::modulename_varname
# - Top Scope Variable ::varname (if second argument is 'global')
# - Module default: ::modulename::params::varname
Expand All @@ -21,8 +23,10 @@
module Puppet::Parser::Functions
newfunction(:params_lookup, :type => :rvalue, :doc => <<-EOS
This fuction looks for the given variable name in a set of different sources:
- Hiera, if available ('modulename::varname')
- Hiera, if available ('modulename_varname')
- Hiera, if available (if second argument is 'global')
- ::modulename::varname
- ::modulename_varname
- ::varname (if second argument is 'global')
- ::modulename::params::varname
Expand All @@ -39,13 +43,20 @@ module Puppet::Parser::Functions

# Hiera Lookup
if Puppet::Parser::Functions.function('hiera')
value = function_hiera(["#{module_name}::#{var_name}", ''])
return value if (not value.nil?) && (value != :undefined) && (value != '')

value = function_hiera(["#{module_name}_#{var_name}", ''])
return value if (not value.nil?) && (value != :undefined) && (value != '')

value = function_hiera(["#{var_name}", '']) if arguments[1] == 'global'
return value if (not value.nil?) && (value != :undefined) && (value != '')
end

# Top Scope Variable Lookup (::modulename::varname)
value = lookupvar("::#{module_name}::#{var_name}")
return value if (not value.nil?) && (value != :undefined) && (value != '')

# Top Scope Variable Lookup (::modulename_varname)
catch (:undefined_variable) do
begin
Expand Down