0
votes

I would like to use Puppet to create a single configuration file. This file can have more than one type of Defined Resource, and can have multiple instances of the same Defined Resource.

For instance,

define host {
    use linux-server
    host_name localhost
    alias localhost
    address 127.0.0.1
}

define host {
    use linux-server
    host_name web1
    alias web1
    address 192.168.0.100
}

define service {
    use local-service
    host_name localhost, web1
    service_description PING
    check_command check_ping!100.0,20%|500.0,60%
}

In this example, there would be two instances of a host Defined Resource and one instance of a service Defined Resource.

This post (Is it possible to define a list of Defined Resource in Puppet?) seems to be a start, but I am having a hard time generalizing it for my goals.

Thanks!

Alan

1

1 Answers

0
votes

I'll point you two options two achieve that.

  1. Use a erb template and a for each structure for building your file. Templating
  2. Use concat, and concat fragments to build your file Concat module

Both options will allow you to construct your file, and it's relatively easy. I think I would use erb template if the file is as simple as you posted it, and a concat structure if the conf file is a heterogeneous mix of several pieces.