Stare at your own problem long enough and it'll come to you.

Move the case to the manifest:

class yum {
:
    case $site {
        'a': { $proxy = 'proxya' }
        'b': { $proxy = 'proxyb' }
        'c': { $proxy = 'proxyc' }
        :
        default: { $proxy = '' }
    }

Then change the "$proxy" to "@proxy" in the templates and lose the first 
line (scope.function_template()). Worked like a charm. 

Then I realized the data actually belonged in Hiera, not in code, so the 
case statement then just decomposed into:

    $proxy = hiera('proxy')


Bret

On Friday, January 17, 2014 10:43:36 AM UTC-5, Bret Wortman wrote:
>
> I'm trying to improve my code reuse a bit, and I have some templates that 
> all start with a common case statement to determine a local proxy (I'm 
> simplifying the file slightly for our discussion here):
>
> file: proxy.erb
> <% proxy = case @site
>    when "a" then "proxya"
>    when "b" then "proxyb"
>    when "c" then "proxyc"
>    when "d" then "proxyd"
> end -%>
>
> This gets included in each template something like this:
>
> file: CentOS-Base.repo.erb
> <%= scope.function_template(["yum/proxy.erb"]) -%>
> :
> [base]
> name=CentOS-$releasever - Base
> :
> <% if $proxy -%>
> proxy=http://<%= $proxy %>:3128
> <% end -%>
> :
>
> The problem is that the "proxy" variable isn't visible from the outer 
> scope. How can I either qualify the outer reference to see it, or somehow 
> export it? Is this possible in some other fashion? I don't want to repeat 
> this code across all the various repo files; adding a proxy shouldn't mean 
> editing every single repo file template when it could mean editing just one 
> file that gets included somehow. At least, that's the goal.
>
> Thanks!
>
>
> Bret
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/988d847f-8f39-4f39-88e9-64039c958002%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to