On 12/23/15 4:14 PM, Tim Dunphy wrote:
> Hello,
>
> How can I require two different types in my manifests? For instance I
> have this setup in one of my modules:
>
> file { "/etc/pki/tls/private/${::hostname}.example.com.key":
> owner => "bacula",
> group => "bacula",
> mode => 0400,
> require => Package["bacula-client","bacula-common"],
> require => File["/etc/pki/tls/private","/etc/pki/tls/certs"],
> source =>
> "puppet:///modules/bacula/${::hostname}/${::hostname}.example.com.key",
> notify => Service["bacula-fd"]
> }
>
> And I want to require both Packages and directories provided by File.
> But when I try that I get this:
>
> Error: Could not retrieve catalog from remote server: Error 400 on
> SERVER: Duplicate parameter 'require' for on
> File[/etc/pki/tls/private/ldap1.example.com.key] at
> /etc/puppet/environments/production/modules/bacula/manifests/config.pp:43 on
> node
ldap1.example.com <
http://ldap1.example.com>
> Warning: Not using cache on failed catalog
> Error: Could not retrieve catalog; skipping run
>
> How do I require both Files and Packages in such a way as to be
> acceptable to puppet?
>
> Thanks,
> Tim
>
Hi Tim,
The key is to use an array.
Such as
file { "/etc/pki/tls/private/${::hostname}.example.com.key":
source =>
"puppet:///modules/bacula/${::hostname}/${::hostname}.example.com.key",
owner => 'bacula',
group => 'bacula',
mode => '0400',
require => [
Package['bacula-client','bacula-common'],
File['/etc/pki/tls/private'],
File['/etc/pki/tls/certs'],
],
notify => Service['bacula-fd'],
}
Since the filesystem is hierarchical in nature, file resources are
implicitly ordered. So if you have a file resource for
'/etc/pki/tls/private' it is automatically done before this file
resource and should not be explicitly required.
Note that this is not same functionality as `mkdir -p`. So if
'/etc/pki/tls' did not exist, the resource for '/etc/pki/tls/private'
would fail and so would this file resource for the key.
You would correctly write your resource as follows.
file { "/etc/pki/tls/private/${::hostname}.example.com.key":
source =>
"puppet:///modules/bacula/${::hostname}/${::hostname}.example.com.key",
owner => 'bacula',
group => 'bacula',
mode => '0400',
require => [
Package['bacula-client','bacula-common'],
File['/etc/pki/tls/certs'],
],
notify => Service['bacula-fd'],
}
Even when requiring multiple resources of the same type, the above
format is the way to go.
Here's a link to make viewing the code a bit nicer.
http://pastebin.com/NpbJT86J
Best regards,
-g
--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile:
+1.206.414.8658