Chris Hirsch
2011-Aug-09 22:40 UTC
[Puppet Users] Question on accessing a variable from another class
Hi all,
I''m trying to promote module re-use so that if I have a module that
deals
with ldap and I have setup variables in a common configuration and I want to
access those same defaulted variables from another module I can easily do
so.
Below is how I''m *attempting* to do this and in MY opinion I think it
should
work ;-) Puppet feels differently and in my node where I include the class
rep I get an error back from puppet saying that it could not find the value
for ldap_cname in my template.
I believe this should work because the rep module includes the config which
includes the ldap::variables_common which should then define $ldap_cname and
the file /etc/rep.xml requires ldap::variables_common before the template.
Can anybody kindly show me the error of my ways?
Thanks!
Chris
-- Examples Modules Below --
modules/ldap/manifests/init.pp:
class ldap {
variables_common
}
class ldap::variables_common {
if( !$ldap_cname) {
$ldap_cname="admin"
}
}
In file modules/rep/manifests/init.pp
class rep {
include config
}
class rep::config {
include ldap::variables_common
file {
"/etc/rep.xml":
ensure => file,
require => Class["ldap::variables_common"],
content => template("rep/test_template.xml.erb");
}
}
modules/rep/templates/test_template.xml.erb
<?xml version="1.0"?>
<configuration>
<test_template cname=''<%= ldap_cname %> />
</configuration>
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Peter Meier
2011-Aug-10 06:24 UTC
Re: [Puppet Users] Question on accessing a variable from another class
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> modules/rep/templates/test_template.xml.erb > <?xml version="1.0"?> > <configuration> > <test_template cname=''<%= ldap_cname %> />The template is in a different scope than ldap::variables_common, so ldap_cname is not directly present like that and you need to use: <test_template cname=''<%scope.lookupvar(''ldap::variables_common::ldap_cname'') %> But for reusable modules etc. I would recommend you to look into hiera [1] and to combine it with parametrized classes as shown in [2], it makes it quite easy and really extensible. ~pete [1] http://www.devco.net/archives/2011/06/05/hiera_a_pluggable_hierarchical_data_store.php [2] http://www.devco.net/archives/2011/06/06/puppet_backend_for_hiera.php -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk5CJC8ACgkQbwltcAfKi3+3lQCdEc5g80XeAE60nBuXlafiy7xE HTcAoLKfAon6XT/e7frTKboQC178hQsq =6jw/ -----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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.