0

I have run into a problem that I am sure is an simple fix but I can't seem to find any resources that explain the behavior correctly. I am building out a new nginx puppet module for automating git server deployment.

I am using a standard nginx setup and am trying to replace the ngnix.conf file.

I call the base class and then request the files become absent before putting the configuration file that I need for my setup.

      class { 'nginx': }

      $nginx_default_files_to_remove = 
       [ 
       "/etc/nginx/conf.d/default.conf",
       "/etc/nginx/default.d/php.conf", 
       "/etc/nginx/nginx.conf" 
       ]

      file { [ $nginx_default_files_to_remove ]: 
      ensure => 'absent', 
      require => Class["nginx"]
      }

This causes the following error to be generated when I run the puppet module on my agent:

Error 400 on SERVER: Duplicate declaration: File[/etc/nginx/nginx.conf] is 
already declared in file /etc/puppet/modules/nginx/manifests/config.pp:331; 
cannot redeclare at /etc/puppet/modules/sf_nginx/manifests/git.pp:18 

It's my understanding that puppet has the ability to remove and replace standard configuration files. Where am I going wrong here?

Husk Rekoms
  • 217
  • 1
  • 4
  • 15
  • 1
    You're treating puppet as a scripting language and thinking in terms of 'commands to execute'. That's not how puppet is supposed to work. You are supposed to define the end / desired state of a resource (here, a file). You have defined that the file should both not exist, and that it should exist in a separate location. A valid error. Why are you bothering to try to delete it if you're going to replace it anyway? –  Aug 23 '18 at 18:07
  • A fundamental flaw in my thoughts behind how puppet works. I was under the assumption I could use an existing module and then once it had been applied, change the default configuration to what I want for my git VM. I guess I'll have to go about this in a different manner. – Husk Rekoms Aug 23 '18 at 19:19
  • 1
    A well designed module will already have methods to allow you to customize the typical parts of a configuration. The [puppet nginx module](https://forge.puppet.com/puppet/nginx) allows you to change things like SSL settings, create new servers, etc without having to reference the nginx config directly. –  Aug 23 '18 at 20:04
  • 1
    thanks, I ended up setting up my module differently (I honestly had though before that puppet installed the modules top down but I was mistaken). It's all working as I want now. – Husk Rekoms Aug 23 '18 at 22:39

1 Answers1

0

As per yoonix's comment, I revised my module to remove the duplication of files and have it working as I want.

Husk Rekoms
  • 217
  • 1
  • 4
  • 15