I''m mucking around with file creation/manipulation and came across the
following:
Let''s say I want to create <some_destination>/etc/hosts, which is
just
a copy of /etc/hosts. I''d have the following class which first
verifies ${dest_dir}/etc exists, then copies the file
class create_hosts {
file {"${dest_dir}/etc/":
owner => "root",
group => "root",
ensure => directory
}
file {"${dest_dir}/etc/hosts":
owner => "root",
group => "root",
mode => 444,
source => "/etc/hosts"
}
}
If I want to create another file in <some_destination>/etc in another
class, I''d have to, again, verify that ${dest_dir}/etc exists, but if
I put that file {} entry in another class, I get the following error:
Could not evaluate classes for holt.ecd.east.sun.com: Duplicate
definition: File[/var/tmp/puppet_test_dir//etc/] is already defined in
file
/import/webtools/ws/wfsaxton/projects/puppet/etc/puppet/manifests/classes/aliases.pp
What''s the best way to get around this? You could put the /etc/
creation in a separate class, I guess, but that seems pretty tedious
to have to have separate classes for every single directory you want
to ''ensure'' exists.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Felix Schäfer
2008-Jun-20 21:59 UTC
[Puppet Users] Re: Avoiding duplicate file definitions
Am 20.06.2008 um 23:50 schrieb Bill:> What''s the best way to get around this? You could put the /etc/ > creation in a separate class, I guess, but that seems pretty tedious > to have to have separate classes for every single directory you want > to ''ensure'' exists.Maybe use virtuals/realize? http://reductivelabs.com/trac/puppet/wiki/FunctionReference#realize Also note that puppet is smart enough to autorequire definitions for parent directories, i.e. having /some/path and /some/path/somefile defined causes the definition for /some/path to be automatically require by the definition for /some/path/somefile. Felix --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Felix,
I don''t think this is the case with parent directories. When I
attempt to execute the following class (FYI, $dest_dir is a variable
that contains the value: ''/var/tmp/puppet_test_dir/'':
class create_dirs {
file {"${dest_dir}/etc/":
owner => "root",
group => "root",
ensure => directory
}
}
I get the following error:
err:
//holt/aggserver/baseclass/create_dirs/File[/var/tmp/puppet_test_dir/etc]/ensure:
change from absent to directory failed: Cannot create
/var/tmp/puppet_test_dir//etc/; parent directory
/var/tmp/puppet_test_dir does not exist
notice:
//holt/aggserver/baseclass/create_dirs/File[/var/tmp/puppet_test_dir/etc/mail]:
Dependency file[/var/tmp/puppet_test_dir//etc/] has 1 failures
On Fri, Jun 20, 2008 at 5:59 PM, Felix Schäfer <schaefer@cypres-it.com>
wrote:>
>
> Am 20.06.2008 um 23:50 schrieb Bill:
>
>> What''s the best way to get around this? You could put the
/etc/
>> creation in a separate class, I guess, but that seems pretty tedious
>> to have to have separate classes for every single directory you want
>> to ''ensure'' exists.
>
> Maybe use virtuals/realize?
http://reductivelabs.com/trac/puppet/wiki/FunctionReference#realize
>
> Also note that puppet is smart enough to autorequire definitions for
> parent directories, i.e. having /some/path and /some/path/somefile
> defined causes the definition for /some/path to be automatically
> require by the definition for /some/path/somefile.
>
> Felix
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
> I don''t think this is the case with parent directories. When I > attempt to execute the following class (FYI, $dest_dir is a variable > that contains the value: ''/var/tmp/puppet_test_dir/'': > > class create_dirs { > file {"${dest_dir}/etc/": > owner => "root", > group => "root", > ensure => directory > } > } > > I get the following error: > > err: //holt/aggserver/baseclass/create_dirs/File[/var/tmp/puppet_test_dir/etc]/ensure: > change from absent to directory failed: Cannot create > /var/tmp/puppet_test_dir//etc/; parent directory > /var/tmp/puppet_test_dir does not exist > notice: //holt/aggserver/baseclass/create_dirs/File[/var/tmp/puppet_test_dir/etc/mail]: > Dependency file[/var/tmp/puppet_test_dir//etc/] has 1 failures >I think you are not quite gettign what Felix said. Puppet will auto set a "require" on the parent directory. This means if the parent directory is not there then puppet will not do anything with that resource. It does not mean itl will auot create a missing directory. In this case becuase you need to create the parent directory you will need to handle it explicitly. I suggest you look at using a virtual resource for this, especially if you need it in serveral places. Generally though once you have defined a resource in a manifest you can just assign a require to ensure that it has been called before the next step. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I think you are not quite gettign what Felix said. Puppet will auto > set a "require" on the parent directory. This means if the parent > directory is not there then puppet will not do anything with that > resource. It does not mean itl will auot create a missing directory. > In this case becuase you need to create the parent directory you will > need to handle it explicitly. I suggest you look at using a virtual > resource for this, especially if you need it in serveral places. > Generally though once you have defined a resource in a manifest you > can just assign a require to ensure that it has been called before the > next step.Correct, I did not get that. Thanks!> > Evan > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---