[Puppet Users] Variable scoping question

2014-01-17 Thread Bret Wortman
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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/926cc7db-5357-44f6-a802-101bf3a986d9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


[Puppet Users] Variable scoping question

2012-08-14 Thread Davíð Steinn Geirsson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi all,

I have a configuration similar to the following (the puppet version is
2.6.16):

node basenode {
$ldapenvironment = "office"
}
node mynode inherits basenode {
include ldap
}

class ldap {
file {
"/etc/openldap/ldap.conf":
owner => "root",
group => "root",
mode => 644,
source => [
"puppet:///modules/ldap/oldap.${ldapenvironment}.conf",
"puppet:///modules/ldap/oldap.conf",
],
sourceselect => first;

}

if ($operatingsystemmajorrelease == "6") {
include ldap::ldap-sssd
}
}

class ldap::ldap-sssd {
file {
"/etc/sssd/sssd.conf":
owner => "root",
group => "root",
mode  => 600,
source => 
"puppet:///modules/ldap/sssd.${ldapenvironment}.conf",
subscribe => Package["sssd"];
}
}


For the ldap class, things work as I expect, $ldapenvironment is
interpolated into the source. However, with the sub-class
ldap::ldap-sssd, the $ldapenvironment variable is empty and puppet
tries to fetch "sssd..conf".

Does variable scoping work differently in includes under node
definitions than under class definitions?

I could not find a good explanation for this in the docs, pointers
would be appreciated.

- -- 
Bestu kveðjur / Best regards,
Davíð Steinn Geirsson

Sími 575 0400 | Síðumúla 32 | 108 Reykjavík
http://www.basis.is/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAqcxwACgkQKXQCZqH9wfw21wCgncbz0Lk2LV4odeSDHFsB53I0
PtsAoI47VD51NOLOOaN9enrlZkSLi82b
=RRZB
-END PGP SIGNATURE-

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.