Ask Your Question

how to merge config files

asked 2015-10-07 17:24:51 -0600

drm509 gravatar image

I have 1 config file which I split into 2: a beginning part and an end part. In the middle I need to create the contents by copying the contents of other config files. My use case is a lumberjack config file, which has a header and in the middle a list of file paths to be monitored, and lastly a footer. The mid part I'm building from other files.

I am trying to create a puppet module which will create this uber config file. I'm passing the file names as an array to the puppet class.

What I want:

exec { 
  cat puppet:///modules/vimrc/vimrc > lumberjack.conf | params.foreach( p => cat p >> lumberjack.conf ) | cat puppet:///modules/vimrc/vimrc >> lumberjack.conf 

Is there sth like this in puppet? I can't find an append command or a way to traverse an input parameter array.

class mess($paramArray)
exec {
  "cat puppet:///modules/config/logconfig2":
  cwd => "/var/tmp/",
  creates => "/var/tmp/lumberjack.conf",  <-there is no append only creates blah  
  path    => ["/usr/bin", "/usr/sbin"]
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-10-07 22:32:37 -0600

llowder gravatar image

You'll want to use the concat module.

It's well documented, but for convenience, here is an example:

class lumberjack_conf{
  $lumberjack_conf = '/var/tmp/lumberjack.conf'

  concat { $lumberjack_conf:
    owner => 'root',
    group => 'root',
    mode  => '0644'

  concat::fragment{ 'lumberjack_header':
    target  => $lumberjack_conf,
    source => 'puppet:///modules/config/logconfig2',
    order   => '01'

  concat::fragment{ 'lumberjack_middle:
    target => $lumberjack_conf,
    content => 'Middle Stuff',
    order  => '15'

  concat::fragment{ 'lumberjack_header':
    target  => $lumberjack_conf,
    source => 'puppet:///modules/config/logconfig2_footer',
    order   => '99'
edit flag offensive delete link more


I've a question about 'order' param, will it be alright if I have more than 1 fragment with the same number value? Can't find an answer to this in the docs.

drm509 gravatar imagedrm509 ( 2015-10-08 15:48:50 -0600 )edit

I'm honestly not certain on that - but I think it will be parse order, alphabetical by title, or in the order that the filesystem lists it. This would be easy to test, an I would recommend testing it or avoiding the use of the same order.

llowder gravatar imagellowder ( 2015-10-08 21:29:14 -0600 )edit

answered 2015-10-07 22:34:33 -0600

lupin gravatar image

Use this module concat

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-10-07 17:24:51 -0600

Seen: 428 times

Last updated: Oct 07 '15