require two different types

15 views
Skip to first unread message

Tim Dunphy

unread,
Dec 23, 2015, 4:14:28 PM12/23/15
to puppet...@googlegroups.com
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
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

--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Garrett Honeycutt

unread,
Dec 23, 2015, 5:52:37 PM12/23/15
to puppet...@googlegroups.com
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

Tim Dunphy

unread,
Dec 23, 2015, 8:20:23 PM12/23/15
to puppet...@googlegroups.com
Hi Garrett,

 That's great. And that explanation makes perfect sense! I understand this a little better now. And using the example you provided works.

Thanks,
Tim

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/567B25A8.4020806%40garretthoneycutt.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages