Ask Your Question
0

Puppet Duplicate declaration error using file template and concat

asked 2016-03-08 03:22:20 -0600

prototyp gravatar image

updated 2016-03-08 08:08:36 -0600

While extending a puppet module which should manage /etc/network/interfaces I am facing the following problem:

The old module just reads some vars from hiera and creates the file with one interface through a template. To remove this limitation I added a hash to hiera containing other interfaces and their params. Through the puppet-concat module I want to add them to the interfaces file.

But if first the file for the template and later the file for the concat gets declared a Duplicate declaration error is thrown.

How can I first use the template and later concat to the file? Or is this not possible?

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: ..../modules/lip_network/manifests/debian.pp:16 cannot redeclare at /etc/puppetlabs/code/modules/concat/manifests/init.pp:179 at .../init.pp:179:5 at .../modules/lip_network/manifests/debian.pp:21

Class Code:

class lip_network::debian
{
  $ipaddress  = $::lip_network::ipaddress
  $netmask    = $::lip_network::netmask
  $gateway    = $::lip_network::gateway
  $dns1       = $::lip_network::dns1
  $domain     = $::lip_network::domain
  $iface      = $::lip_network::iface

  package { 'resolvconf':
    ensure  => latest,
  }

  file { '/etc/network/interfaces':
    mode    => '0644',
    owner   => 'root',
    content =>  template("${module_name}/interfaces.erb"),
  }
  concat { '/etc/network/interfaces':
    ensure => present,
  }
  $interface_configs = hiera_hash(lip_network_multi_interfaces::interfaces)
  $interface_list = keys($interface_configs)

  concat::fragment { "test_interfaces":
      target  => '/etc/network/interfaces',
      content => 'auto em0\niface em0 inet static',
      order   => "10"
  }


  # apparently /etc/init.d/networking does not regenerate
  exec { 'iface restart':
    command     => "ifdown ${iface} ; ifup ${iface}",
    refreshonly => true,
    subscribe   => File['/etc/network/interfaces'],
  }
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-03-08 08:09:16 -0600

I don't think you can do that, and again, it's much better to have all of this stuff inside the template. There's still no need to be using concat fragments here.

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

Stats

Asked: 2016-03-08 03:22:20 -0600

Seen: 559 times

Last updated: Mar 08 '16