On Fri, Feb 11, 2011 at 12:42:58PM -0500, Matthew Pounsett wrote:
> I'm having an issue solving dependencies inside defines, where the paths to 
> various resources are variable.  It seems like puppet isn't expanding all of 
> the variables when it constructs the catalog, so it's unable to find the 
> resources necessary to build things in the right order.
> 
> I've constructed a simple proof of concept to demonstrate the problem.  I'm 
> hoping someone can provide some advice on how this case should be handled, 
> because clearly I've misunderstood how puppet is intended to be used to 
> handle this sort of case.
> 
> Here is my site.pp, with a single machine loading up the module that builds a 
> standard service.  Each instance of the service has its own homedir with its 
> own data, logs, etc.
> 
> node "puppet-bsd2.virtual" {
>     include service
>     service::app {
>         "first":
>             service_num =>  "1";
>         "second":
>             service_num =>  "2";
>     }
> }
> 
> Here's the init.pp manifest for the 'service' module.  It includes the 
> 'devices' module which is used for creating device files in a chroot 
> environment, and sets up the homedir for each instance of the service.
> 
> include devices
> class service {
>     file {
>         "/opt":
>             ensure => directory,
>             owner => root,
>             group => wheel,
>             mode => 755;
>         "/opt/home":
>             ensure => directory,
>             owner => root,
>             group => wheel,
>             mode => 755;
>     }
>     define app (
>         $homedir = "/opt/home",
>         $service_num
>     ) {
>         file {
>             "$homedir/${service_num}":
>                 ensure  =>  directory,
>                 owner   =>  root,
>                 group   =>  wheel,
>                 mode    =>  0750;
>             "$homedir/${service_num}/dev":
>                 ensure  =>  directory,
>                 owner   =>  root,
>                 group   =>  wheel,
>                 mode    =>  0750;
>         }
>         devices::device_node {
>             "${homedir}/${service_num}/dev/null":
>                 dir     => "$homedir/${service_num}/dev/";
>             "${homedir}/${service_num}/dev/random":
>                 dir     => "$homedir/${service_num}/dev/";
>         }
>     }
> }
> 
> And finally, the devices module.  
> 
> class devices {
>     define device_node (
>         $dir
>     ) {
>         exec {
>             "create-device-${name}":
>                 creates => "${name}",
>                 cwd => ${dir},
>                 command => "/usr/bin/touch ${name}",
>         }
>     }
> }
> 
> 
> The problem is one of order of operations.  With the above manifests, puppet 
> always tries to write the device files before it creates the 'var' directory 
> that contains them.  According to the 'require' documentation, 'cwd' inside 
> an exec clause should auto-require the directory referenced.  This wasn't 
> working, and so I tried to change the 'cwd' to a 'require => File...' in 
> order to make it more explicit.  This is what exposed the real problem to me:
> 
> Feb 11 17:18:40 puppet-bsd2 puppet-agent[68963]: Could not run Puppet 
> configuration client: Could not find dependency File[/opt/home/2/dev/] for 
> Exec[create-device-/opt/home/2/dev/null] at 
> /usr/local/etc/puppet/production/modules/devices/manifests/init.pp:12
> 
> How do other people deal with these sorts of dependencies, where the files 
> and directories being created have variable paths based on the arguments 
> passed to a definition?  Is there a better way to get where I'm trying to go 
> with this?
> 
> Any clue is highly appreciated.
> 

caution - newbie replying

what if you create the device directories within
devices::device_node instead of service::app?  somehow you have to
parse out the path components of $dir and ensure them one by one.
Why is it puppet does not have a nice trick for "mkdir -p"?








> -- 
> 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.

-- 

-ashley

Did you try poking at it with a stick?

-- 
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.

Reply via email to