Hi,
in this simplified example, I''m trying to create directories, and add
each directory name into a variable,
later on, generate a file which its content should be the directory
names, but it doesn''t work....
any help appreciated.
Thanks,
Ohad
node default {
include b
}
class a {
file{"/tmp/dirs": content => template("/tmp/dirs.erb")}
}
class b {
$dirs = ["dummy"]
dir{["/tmp","/tmp/a","/tmp/b"]:}
include a
}
define dir() {
file {$name: ensure => directory }
$b::dirs += $name
}
-----
/tmp/dirs.erb:
<%= scope.lookupvar("b::dirs") %>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Joel Heenan
2009-May-29 06:26 UTC
[Puppet Users] Re: variable scope with define and friends...
I might be wrong Ohad but my understanding is that puppet configurations are
declarative and therefore have to be compiled. It probably helps to stop
thinking about your define as being a function, executed at run time, and
think of it as a macro that is substitued all over the place. It is not a
function being run.
You could write a custom function for this but I think the easiest is if you
simply do
$dirs =["/tmp","/tmp/a","/tmp/b"]
dir { $dirs: }
then it will be available to your template. I haven''t tried this though
it
may not work.
Joel
On Fri, May 29, 2009 at 3:55 PM, Ohad Levy <ohadlevy@gmail.com> wrote:
> Hi,
>
> in this simplified example, I''m trying to create directories, and
add each directory name into a variable,
> later on, generate a file which its content should be the directory names,
but it doesn''t work....
>
> any help appreciated.
>
> Thanks,
> Ohad
>
>
> node default {
> include b
> }
>
> class a {
> file{"/tmp/dirs": content =>
template("/tmp/dirs.erb")}
> }
>
> class b {
> $dirs = ["dummy"]
> dir{["/tmp","/tmp/a","/tmp/b"]:}
> include a
> }
>
> define dir() {
> file {$name: ensure => directory }
> $b::dirs += $name
> }
>
> -----
> /tmp/dirs.erb:
> <%= scope.lookupvar("b::dirs") %>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Ohad Levy
2009-May-29 06:57 UTC
[Puppet Users] Re: variable scope with define and friends...
On Fri, May 29, 2009 at 2:26 PM, Joel Heenan <joelh@planetjoel.com> wrote:> I might be wrong Ohad but my understanding is that puppet configurations > are declarative and therefore have to be compiled. It probably helps to stop > thinking about your define as being a function, executed at run time, and > think of it as a macro that is substitued all over the place. It is not a > function being run. >I guess the function in this case is the template / notice or what ever you''ll replace it with...> > You could write a custom function for this but I think the easiest is if > you simply dothat wont help either, because you cant control when the function would run, same as templates. Unless I''ll write a function which reads the manifests file again. :(> > > $dirs =["/tmp","/tmp/a","/tmp/b"]> > dir { $dirs: }my example was a simple one, the real usage case wont work with this workaround as I cant define them in one place> > > then it will be available to your template. I haven''t tried this though it > may not work. > > Joel > > > On Fri, May 29, 2009 at 3:55 PM, Ohad Levy <ohadlevy@gmail.com> wrote: > >> Hi, >> >> in this simplified example, I''m trying to create directories, and add each directory name into a variable, >> >> later on, generate a file which its content should be the directory names, but it doesn''t work.... >> >> any help appreciated. >> >> Thanks, >> Ohad >> >> >> node default { >> include b >> } >> >> class a { >> file{"/tmp/dirs": content => template("/tmp/dirs.erb")} >> } >> >> class b { >> $dirs = ["dummy"] >> dir{["/tmp","/tmp/a","/tmp/b"]:} >> include a >> } >> >> define dir() { >> file {$name: ensure => directory } >> $b::dirs += $name >> } >> >> ----- >> /tmp/dirs.erb: >> <%= scope.lookupvar("b::dirs") %> >> >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ohad Levy
2009-May-29 08:56 UTC
[Puppet Users] Re: variable scope with define and friends...
replying to myself...
so it seems the problem is not the varialbe scope, rather then the template
function.
the following code works:
node default {
include a
include b
}
class a {
$dirs = ""
dir{["/tmp","/tmp/a","/tmp/b"]: before =>
File["/tmp/dirs"]}
}
class b {
file{"/tmp/dirs": content => $a::dirs}
#file{"/tmp/dirs": content =>
template("/tmp/dirs.erb")}
}
define dir() {
$a::dirs += " $name"
file {$name: ensure => directory }
}
if anyone has any idea how to make this work with a template, that would be
great.
Thanks,
Ohad
On Fri, May 29, 2009 at 1:55 PM, Ohad Levy <ohadlevy@gmail.com> wrote:
> Hi,
>
> in this simplified example, I''m trying to create directories, and
add each directory name into a variable,
> later on, generate a file which its content should be the directory names,
but it doesn''t work....
>
> any help appreciated.
>
> Thanks,
> Ohad
>
>
> node default {
> include b
> }
>
> class a {
> file{"/tmp/dirs": content =>
template("/tmp/dirs.erb")}
> }
>
> class b {
> $dirs = ["dummy"]
> dir{["/tmp","/tmp/a","/tmp/b"]:}
> include a
> }
>
> define dir() {
> file {$name: ensure => directory }
> $b::dirs += $name
> }
>
> -----
> /tmp/dirs.erb:
> <%= scope.lookupvar("b::dirs") %>
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---