example42 / puppet-tp

Tiny Puppet - The Universal Installer
http://tiny-puppet.com
Apache License 2.0
68 stars 21 forks source link

tp::install is failing when defining configuration file source in conf_hash #70

Closed findmyname666 closed 4 years ago

findmyname666 commented 4 years ago

Expected Behavior

To Create configuration file.

Actual Behavior

The code is failing on:

Error: Validation of File[/etc/process-exporter/config.yaml] failed: You cannot specify more than one of content, source, target (file: /etc/puppetlabs/code/environments/production/modules/tp/manifests/conf.pp, line: 339)

With added logging:

--- /etc/puppetlabs/code/environments/production/modules/tp/manifests/conf.pp   2020-02-19 15:33:25.591810484 +0000
+++ /tmp/conf.pp    2020-02-19 15:33:18.343745299 +0000
@@ -333,6 +333,8 @@
     notify       => $manage_notify,
     validate_cmd => $manage_validate_cmd,
   }
+  $config_file_parameters = pick($settings[config_file_params],{})
+  notice("path: ${manage_path},file params: ${file_params}, config file parameters: ${config_file_parameters} ")

   file { $manage_path:
     * => $file_params + pick($settings[config_file_params],{})

We can see that there are really source and content in var $file_params but content is empty.

Notice: Scope(Tp::Conf[prometheus-process-exporter]): path: /etc/process-exporter/config.yaml,file params: {ensure => latest, source => puppet:///site/showmax_tinydata/prometheus-process-exporter, content => , path => /etc/process-exporter/config.yaml, mode => 0644, owner => root, group => root, require => Package[prometheus-process-exporter], notify => Service[prometheus-process-exporter], validate_cmd => }, config file parameters: {}

Steps to Reproduce the Problem

  1. Pass following data to tp::install:
    packages:
    prometheus-process-exporter:
    ensure: 'latest'
    data_module: 'my_tinydata'
    conf_hash:
      'prometheus-process-exporter':
         source: 'puppet:///site/my_tinydata/prometheus-process-exporter'

When i change ensure to present everything works + when i passed ensure to conf_hash:

  prometheus-process-exporter:
    ensure: 'latest'
    data_module: 'showmax_tinydata'
    conf_hash:
      prometheus-process-exporter:
        ensure: 'file'
        source: 'puppet:///modules/showmax_tinydata/prometheus-process-exporter/nginx.yaml'
  1. Execute tp::install
    $packages.each |$package_name, $attributes| {
    tp::install { $package_name:
      * => $attributes,
    }
    }

FYI my tinydata:

---
  prometheus-process-exporter::settings:
    package_name: 'prometheus-process-exporter'
    service_name: 'prometheus-process-exporter'
    config_file_path: '/etc/process-exporter/config.yaml'

Specifications

Please add this info:

alvagante commented 4 years ago

@findmyname666 curious case, maybe due to custom tinydata. Can you tell me if changing line 338 in tp::conf https://github.com/example42/puppet-tp/blob/master/manifests/conf.pp#L338 from:

findmyname666 commented 4 years ago

Hi @alvagante , Nope still the same. I think the issue is that it tries to set latest as ensure for file. Even though error doesn't match it :man_shrugging:

alvagante commented 4 years ago

@findmyname666 oh , you're right, the problem is here: https://github.com/example42/puppet-tp/blob/master/manifests/install.pp#L294 . Honestly I almost never used the conf_hash param in tp::install. Have to fix it, thanks for the workaround anyway.

findmyname666 commented 4 years ago

Honestly I almost never used the conf_hash param in tp::install. Actually i think that it is neat feature ;)

alvagante commented 4 years ago

@findmyname666 can you please check if https://github.com/example42/puppet-tp/commit/6157efa46b12d3228ec14d421b5c99ab2a4f481c fixes the issue?

findmyname666 commented 4 years ago

Hi @alvagante , busy time ! sorry to don't get back to you ... i was thinking can you insert also data_module to dir_defaults please?

  $dir_defaults = {
    'ensure'        => $ensure,
    'ensure'        => tp::ensure2dir($ensure),
    'settings_hash' => $settings,
    'data_module'  => $data_module
  }
alvagante commented 4 years ago

Good catch @findmyname666 , and good that someone is using custom tinydata. Added in the referenced commit.

findmyname666 commented 4 years ago

@alvagante can you publish it on forge?

alvagante commented 4 years ago

@findmyname666 pushed version 2.4.2