1

I declared this in mon.pp file

  $pem_file_path = "/etc/ssl/private/${::environment}.pem"
  $defaults = hiera_hash('defaults')
  $subscription_id = $defaults['subscription_id']
  $pem_file_content = hiera('nb_monitoring::azure_limits_sa::pem_file_content')
  file { $pem_file_path:
  ensure  => 'present',
  owner   => 'root',
  group   => 'root',
  mode    => '0600',
  content => $pem_file_content
  }
  }

And in another different module > azure_limits_sa.pp i am using same thing

  # From ${::env}/mon.yaml
  $pem_file_content = hiera('nb_monitoring::azure_limits_sa::pem_file_content')

  file { $pem_file_path:
  ensure  => 'present',
  owner   => 'root',
  group   => 'root',
  mode    => '0600',
  content => $pem_file_content
 }

When I run puppet I get this Error: Error: Duplicate declaration: File[/etc/ssl/private/dev1.pem] is already declared in file /tmp/vagrant-puppet/modules-2134b0ea668add24edb5ea5a9ee9f8a1/nb_tsg/manifests/mon.pp:25; cannot redeclare at /tmp/vagrant-puppet/modules-2134b0ea668add24edb5ea5a9ee9f8a1/nb_monitoring/manifests/azure_limits_sa.pp:43 on node dev1-mon1

How do i solve this?

Dheeraj
  • 297
  • 1
  • 5
  • 17
  • Is there any specific reason to declare same file with same content in two different classes? If not I'll suggest you to just `ensure` the file is present in one class while declare it in other(check for the order though). – harshad Feb 01 '16 at 09:52

2 Answers2

1

Best way is to refactor with a separate class for the file resource so that you don't end up with the same resource in two classes on the same host.

Alternatively, you can use virtual resources, with this in both classes:

 @file { $pem_file_path:
  ensure  => 'present',
  owner   => 'root',
  group   => 'root',
  mode    => '0600',
  content => $pem_file_content
 }
 realize File[$pem_file_path]
Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • Do I need to change this in both files or I can change only in one file? – Dheeraj Jan 30 '16 at 18:12
  • `$pem_file_path = "/etc/ssl/private/${::environment}.pem" $defaults = hiera_hash('defaults') $subscription_id = $defaults['subscription_id'] $pem_file_content = hiera('nb_monitoring::azure_limits_sa::pem_file_content') @file { $pem_file_path: ensure => 'present', owner => 'root', group => 'root', mode => '0600', content => $pem_file_content } realize File[$pem_file_path] }` – Dheeraj Jan 30 '16 at 18:38
1

This somehow goes against puppet nature. Why would you want to manage same file on two different places and apply it all on the same node? If I'm correct, you are getting same data from Hiera in both puppet manifests and passing them to File resource. Therefore, one could be safely removed or you can decouple it in third puppet manifest which would have notifying relationship to File (~>) whenever something changes to apply those changes back to the file

Bakir Jusufbegovic
  • 2,806
  • 4
  • 32
  • 48