On Wednesday, June 4, 2014 10:34:11 AM UTC-5, Vadym Chepkov wrote:
>
>
>
> On Wednesday, June 4, 2014 9:52:44 AM UTC-4, Felix.Frank wrote:
>>
>> Hi, 
>>
>> On 06/04/2014 03:32 PM, Vadym Chepkov wrote: 
>> > File[ensure=>directory] -> Mount[type=nfs,ensure=>mounted] 
>> > 
>> > Is this possible or I have to maintain two sets of data? 
>>
>> no, that is fine. The 'puppet magic' you are looking for is a defined 
>> type that accepts all the parameters you want to declare in your data. 
>> The implementation of the define should then "translate" them into the 
>> file and mount resources you want. 
>>
>> See 
>> http://docs.puppetlabs.com/puppet/latest/reference/lang_defined_types.html 
>>
>> HTH, 
>> Felix 
>>
>
> Thank you, that is indeed what I need.
>
> I have one more related question though. Is it possible to create the 
> whole path, similar to mkdir -p for the mount points using File resource?
> i.e. I will use /apps/oracle as a mount point. I want puppet to create 
> /apps for me. since /apps is not going to be a mount point, I would have to 
> track it separately and I would like to avoid it.
> I suppose I can create yet another attribute, like "is_mount: false", but 
> I wonder if there is a better way to accomplish it?
>
>

Puppet does not directly support automatic declaration of parent 
directories, but it should not be too hard to implement using (again) a 
defined type.  Something along these lines could probably be made to work:

define mymodule::recursive_file ($ensure => 'directory') {
  $parent = regsubst($title, '^(.*)/[^/]+$', '\1')

  file { $title: ensure => $ensure }

  if $parent {
    mymodule::recursive_file { $parent: }
  }
}

You then use it in any class or definition, like so:

mymodule::recursive_file { '/grandparent/parent/file':
  ensure => 'file'
}

That could be gussied up with additional attributes (mode, owner, etc.).  
The problem with that is it easily lends itself to creating duplicate 
declarations.  Consider:

file { '/etc': ensure => 'directory' }
mymodule::recursive_file { '/etc/somepackage/somepackage.conf':
  ensure => 'file'
}

You end up with File['/etc'] being declared twice, which Puppet will not 
accept.

Using an Exec to run 'mkdir -p' is in some ways better, but in other ways 
worse.  It reduces your exposure to duplicate declaration issues, but at 
the price of exposing you to the possibility of an inconsistent catalog.  
Consider this, for example:

exec { 'mkdir -p /etc/somepackage':
  creates => '/etc/somepackage'
}
->
file { '/etc/somepackage/somepackage.conf':
  ensure => file
}

[... somewhere else ...]

file { '/etc/somepackage':
  ensure => 'absent'
}

That *still* suffers from the problem that you are attempting to manage the 
same physical resource (directory /etc/somepackage) via two different 
Puppet resources, but Puppet can no longer recognize the problem because 
you have disguised it.  Your catalog will be compiled, but Puppet cannot 
reliably apply it because it is internally inconsistent.

If you are careful to avoid inconsistencies then you can nevertheless make 
something like that work for you, but in that case you are on your own.

The alternative, and in many respects the true Puppet way, is to explicitly 
manage those files and directories you intend to manage, and only those.  
Remember always that building Puppet manifests is an exercise in modeling, 
not in scripting.


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/e4bd79b9-751d-4d7c-b180-5f4f499c87ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to