Ask Your Question

ERROR: Could not open downloaded file

asked 2017-03-06 13:06:08 -0500

updated 2017-03-07 02:35:59 -0500

*Edit: Content of class filebeat::install_filebeat added *

I have 2 classes in my puppet module, class filebeat and class filebeat::install_filebeat inherits filebeat.

In class filebeat I want to download a properties file and save it in an specific path so I do:

exec{ 'get_properties_file':
command => "/usr/bin/curl -o ${properties_path} '${download_url}'",
creates => $properties_path,

file{ $properties_path:
mode    => '644',
target  => $properties_path 
require => Exec["get_properties file"],

This is working fine, and the file is downloaded to the $properties_path

Then in my class filebeat::install_filebeat I have:

class filebeat::install_filebeat inherits filebeat{

  $file = file($properties_path)
  $properties_lines = split( $file, '\r')
  $host_line = grep($properties_lines, '^host=.*')
  $token_line = grep($properties_lines, '^token=.*')
  $host_splited = split($host_line[0], '=')
  $token_splited = split($token_line[0], '=')
  $token = join(delete_at($token_splited,0),"=")
  $host = join(delete_at($host_splited,0),"=")

 file { '/etc/filebeat/filebeat.yml':
      ensure  => 'present',
      owner   => 'root',
      group   => 'root',
      mode    => '644',
      purge   => true,
      content => template("filebeat/${filebeat_template}"),

 service { 'filebeat':
    ensure     => running,
    enable     => true,
   hasstatus  => true,
   hasrestart => true,

File['/etc/filebeat/filebeat.yml'] -> Service['filebeat'] 

This works fine if the file has been savev in the $propertiespath in a previous execution but when I try to do everything at once by adding in my class filebeat *include filebeat::installfilebeat*

I keep getting the error: "Error: Could not find any files from [properties_path]"

It seems to me that puppet is trying to do file($properties_path) before doing the download first, but I really don't how to solve it..

Any help will be awsome!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-07 02:04:16 -0500

joshc gravatar image

file($properties_path) is a function evaluated during catalog compilation (as opposed to catalog application), and if the file doesn't exist, compilation will fail.

I'm guessing you want to do $file = $properties_path, so set the value of the file variable to whatever properties_pathis set to? See also the variables section in our docs:

edit flag offensive delete link more


What I want to do is to download the file and the open it as a string. Is it possible to do that in a same catalog compilation? I edited the question to add the content of my class filebeat::install_filebeat

platypus gravatar imageplatypus ( 2017-03-07 02:36:24 -0500 )edit

@joshc, do you have any further advice regarding this?

platypus gravatar imageplatypus ( 2017-03-08 04:43:32 -0500 )edit

You could use `file` resource with a `source` parameter, e.g. `source => 'puppet:///mymodule/myfile.txt'`, or one of the many `staging` modules. But why not use the `file` function to include the string in the catalog, e.g. `$file = file('/absolute/path/to/file.txt')`?

joshc gravatar imagejoshc ( 2017-03-09 10:59:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-03-06 13:06:08 -0500

Seen: 20 times

Last updated: Mar 07