Issue #20813 has been updated by Igor Muratov.
Status changed from Unreviewed to Closed
Assignee set to Igor Muratov
This is invalid bug report. The code above is wrong and here is fix to make it
work as expected:
- if ( $parent != "" and ! defined(File["$parent"])) {
+ if ( $parent != "" and ! defined(Make_dir["$parent"])) {
----------------------------------------
Bug #20813: Defined type with recursion fails with duplicate declaration
https://projects.puppetlabs.com/issues/20813#change-92207
* Author: Igor Muratov
* Status: Closed
* Priority: Normal
* Assignee: Igor Muratov
* Category:
* Target version:
* Affected Puppet version: 2.7.21
* Keywords: defined types, recursion, mkdir_p
* Branch:
----------------------------------------
First of all let me say it fails in some situations, not always. Here is the
code which I have:
<pre>
class filesystem {
File {
ensure => directory,
mode => '0755',
owner => 'root',
group => 'root',
}
# Recursive function creates chain of objects
define make_dir($owner=undef, $group=undef, $mode=undef) {
file { $name:
ensure => directory,
mode => $mode,
owner => $owner,
group => $group,
}
# Take parent directory name
$parent = regsubst($name, '(.+)(/[^/]+)$', '\1')
# Recursive call if object does not exist
if ( $parent != "" and ! defined(File["$parent"])) {
make_dir { $parent:
mode => $mode,
owner => $owner,
group => $group,
}
File["$parent"] -> File["$name"]
}
}
}
class filesystem::common inherits filesystem {
make_dir { [
'/usr/local/bin',
'/usr/local/etc',
]:
}
}
</pre>
So, when I do have two directories with the same parent directory, the class
will fail:
<pre>
Mogul:manifests user$ minicatv example.com filesystem::common
notice: looking up example.com...
err: Duplicate declaration: Filesystem::Make_dir[/usr/local] is already
declared in file /home/user/Dvl/my_test/modules/filesystem/manifests/init.pp at
line 63; cannot redeclare at
/home/user/Dvl/my_test/modules/filesystem/manifests/init.pp:63 on node
example.com
err: Try 'puppet help minicat compile' for usage
There is no issue with /usr but with the longest common part of items. The
workaround is to add the parent directory into the list like that:
/usr/local
/usr/local/bin
/usr/local/etc
</pre>
That case all directory objects, including /usr, will be created with no
errors. It is not obvious to me where and why puppet fails and I only assuming
it could be a bug.
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.