I get a lot of: "failed: You cannot specify more than one of content, source, target at.."

Hi all, I am trying to write a module that it depends to multiple files. now while my code is parser validated and it essentially comprises of:

class elkstack {
package { 'filebeat' :
ensure => 'installed',
source => " puppet:///modules/elkstack/filebeat-1.3.1-x86_64.rpm ",
}
service { 'filebeat' :
ensure   => 'running',
enable   =>  'true',
require => Package['filebeat'],
}
file { '/etc/pki/tls/certs/logstash-forwarder.crt':
ensure => 'present',
content  => "puppet:///modules/elkstack/logstash-forwarder.crt",
}
file { '/etc/filebeat/filebeat.yml' :
ensure  => 'presnet',
content => "puppet:///modules/elkstack/filebeat.yml",
require =>  Package['filebeat'],
}


I am getting the subject error on the second file resource declaration that refer basically to the same dir as /modules/elkstack/files/... I tried to search the Internet for any same case scenario but non existed. Note that I run puppet apply /modules/elkstack/example/init.pp --noop on the puppet master when getting this error...Can somebody help? as it has been bugging me for the last hour or two please...

edit retag close merge delete

1

Looks like you're mixing your source and content params there, you'll want source for each one of them. content is used to provide the actual contents of the file rather than a file location. Not sure if it would solve the error, it would be useful if you posted the full error.

( 2017-06-28 08:11:00 -0500 )edit

Sort by » oldest newest most voted

I think you are missing something fundamental about the file resource, that will make nikdoof's answer much clearer..

Above, you are using the content parameter. If you look at the docs for the content parameter of the file resource, you will see the following description:

The desired contents of a file, as a string. This attribute is mutually exclusive with source and target.

what you seem to actually want to do is use the source parameter, described here:

A source file, which will be copied into place on the local system. This attribute is mutually exclusive with content and target. Allowed values are:

•puppet: URIs, which point to files in modules or Puppet file server mount points.

•Fully qualified paths to locally available files (including files on NFS shares or Windows mapped drives).

•file: URIs, which behave the same as local file paths.

•http: URIs, which point to files served by common web servers

If you notice in the definition for content, it mentions that it's mutually exclusive with source and target. I don't directly see you using multiple source/target in the above definition. do you happen to have a 'global' value set for one of those values somewhere else in your code base? something like

File {
source => '/some/path'
}


or

File {
target=> '/some/path'
}


If you have one of those defined somewhere in your scope, then that 'global' assignment of a parameter is interfering with your specific file resource, for the one that is failing, try explicitly assigning them with undef, like this

  file { '/etc/filebeat/filebeat.yml' :
ensure  => 'presnet',
content => "puppet:///modules/elkstack/filebeat.yml",
target => undef,
source => undef,
require =>  Package['filebeat'],
}


If that fixes your 'error', then something else is setting the parameters by default. You still probably don't want the 'content' of the file to be the string puppet:///modules/elkstack/filebeat.yml, so you'll probably need to switch that to source instead of content

more

DarylW, Thanks for clarifications.However, as the error suggests it mutually address content and source the same way...what I tried to replicate was changing the 'content' parameter with 'source' to double-check and added the undef ...result was the same :(

( 2017-06-30 23:20:14 -0500 )edit

Nikdoof, The more I searched reviewed the docs.puppet.com, the closer I got to your answer. Although I would not call myself an expert in puppet, could say that the culprit will be the directory addressing in puppet where the granulation ends there and not to the file level ...Is that right ? But again there are a lot of scenarios that under one single class declaration you may require more than one file to declare ...I can give numerous examples but enough to say the<package> .conf and <package>.service files of a package; or configs that will go for places like var or tweaks that you need to have under /etc/sysctl.conf ...all in all chances that you get more than a file to declare is hugely possible...a feature request? Maybe ...</package></package>

more