Skip to content

Instantly share code, notes, and snippets.

@clintmiller
Last active May 6, 2016 17:19
Show Gist options
  • Save clintmiller/8772a1cf277de2e57aa11a33ef61c3b5 to your computer and use it in GitHub Desktop.
Save clintmiller/8772a1cf277de2e57aa11a33ef61c3b5 to your computer and use it in GitHub Desktop.
Puppet - How to deal with a Duplicate Resource Declaration error
# ORIGINAL ROLES
class role::web {
# snip ...
sysctl { "net.core.somaxconn":
# snip ...
value => 8192
}
# snip ...
}
class role::redis {
# snip ...
sysctl { "net.core.somaxconn":
# snip ..
value => 1024
}
# snip ...
}
# When you try to include both of these classes in a node (that plays both roles, for instance), you're going to have problems:
# Error: Duplicate declaration: ______ (whatever resource) is already declared in file ...
# defines.pp
define base::sysctl::somaxconn ($value=undef) {
if $value {
$ensure = 'present'
} else {
$ensure = 'absent'
}
sysctl{ "net.core.somaxconn":
ensure => $ensure,
permanent => 'yes',
value => $value
}
}
# NEW ROLES
class role::web {
# snip ...
@base::sysctl::somaxconn { 'web': value => 8192 }
# snip ...
}
class role::redis {
# snip ...
@base::sysctl::somaxconn { 'redis': value => 1024 }
# snip ...
}
# nodes.pp
node 'web1' {
include role::web
realize Base::Sysctl::Somaxconn['web']
}
node 'redis1' {
incldue role::redis
realize Base::Sysctl::Somaxconn['redis']
}
node 'web_and_redis1' {
include role::redis
include role::web
realize Base::Sysctl::Somaxconn['web']
# You can also "pick" the redis role's somaxconn by passing the
# title of the resource defined by the redis role in the call to
# `realize` above. That happens to be 'redis' in this case.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment