On Monday, November 17, 2014 2:06:25 AM UTC-6, Rajgourav Jain wrote:
>
> Hi,
>
> I have written two defined type and trying to use some variables between 
> them. 
>
> ----foo/manifest/init.pp ------------
> define foo( $x=undef, $y=undef)
> {
>
>   if $x == undef {
>    $xx = $defualt_x
>   } else {
>     $xx  = $x
>   }
>
> if $y == undef {
>    $yy $defualt_y
>   } else {
>     $yy= $y
>   }
>
>  fooinstall {$xx:}
> }
>
>
> --------------foo/manifest/install.pp------------------- 
> define foo::install (){
>   if  $yy= "some text" 
>   { 
>      puppet code here
>    }
>   else {
>      puppet code here 
>   }
> }
>
>
> ------ sites.pp ----
> node 'hostnam-l.domain.com'
> {
> foo { "Aname" :
>    $x => a,
>    $y => b,
>  }
> }
>
> Could you suggest how can I make this code work. I am not able to access 
> $xx and $yy in defined type foo::install.
>


No, you're not.  They are not in scope 
<https://docs.puppetlabs.com/puppet/3/reference/lang_scope.html> there.  
Your simpler options include:

   1. Passing the values as parameters of foo::install, or
   2. merging the foo::install defined type into the foo defined type 
   (provided foo::install is declared only in foo).

On the other hand, the pattern you are using looks like it might be one 
better served by classes.  This is the case if it doesn't make sense for 
any node to have two different Foo or Foo::Install resources.  In that 
event, if you change at least foo to a class then foo::install can refer to 
its variables by their qualified names: $::foo::xx (or usually $foo::xx 
works too), etc..


John

-- 
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/535e5556-9ade-470a-ba26-25cad1049d37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to