Puppet/Ruby File.exists?() not working on Windows [closed]

asked 2015-07-09 06:07:05 -0500

helge gravatar image

updated 2015-07-09 09:37:24 -0500

Hello community,

this the first time I (have to) use ask, but now I seem to be stuck with a rather trivial problem on Windows, checking for an existing file with ruby.

May goal is to load a YAML file from disk into a puppet hash. Problem: Ruby File.exists does not to be working as expected for me, it is used in the loadyaml() function of puppet stdlib.

Do debug this, I use the following class with inline template:

inline_template('<% if File.exist?(@version_yml) -%>true<% else -%>false<%end -%>')

Since the file is created in the puppet run, it should exist.

class debug::fileexists ($destination, $version) {
  $yml = "#managed by puppet\n---\nversion: ${version}\n"
  validate_absolute_path($destination)
  $version_yml = "${destination}/version.yml"

  # workaround: use inline ruby to test for existing version file
  notify { 'filepath':
    message => "YAML- File: ${version_yml}"
  }
  ->
  file { $version_yml:
    ensure  => present,
    mode    => '777',
    content => $yml,
  }
  ->
  notify { 'inline_template':
    message => inline_template('<% if File.exist?(@version_yml) -%>true<% else -%>false<%end -%>')
  }
}

However, my puppet output looks like this:

C:\Program Files\Puppet Labs\Puppet\bin>puppet apply c:\debug.pp
Notice: Compiled catalog for wstest02.int.m-box.de in environment production in 0.28 seconds
Notice: YAML- File: C:/test/version.yml
Notice: /Stage[main]/Debug::Fileexists/Notify[filepath]/message: defined 'message' as 'YAML- File: C:/test/version.yml'
Notice: /Stage[main]/Debug::Fileexists/File[C:/test/version.yml]/ensure: created
Notice: false
Notice: /Stage[main]/Debug::Fileexists/Notify[inline_template]/message: defined 'message' as 'false'
Notice: Finished catalog run in 0.19 seconds

Sure enough, the file exists:

C:\Program Files\Puppet Labs\Puppet\bin>dir C:\test\version.yml
 Volume in drive C has no label.
 Volume Serial Number is 0095-8D6F

 Directory of C:\test

09.07.2015  11:24                34 version.yml
               1 File(s)             34 bytes
               0 Dir(s)  651.091.238.912 bytes free

Running the same code in IRB, works as well:

irb(main):001:0> version_yml = 'C:/test/version.yml'
=> "C:/test/version.yml"
irb(main):002:0> File.exists?(version_yml)
=> true
irb(main):003:0> require 'yaml'
=> true
irb(main):004:0> YAML.load(File.open(version_yml))
=> {"version"=>1}

Versions:

C:\Program Files\Puppet Labs\Puppet\bin>facter
architecture => x64
dir => C:\Program Files\Puppet Labs\Puppet\facter
env_windows_installdir => C:\Program Files\Puppet Labs\Puppet
facterversion => 2.3.0
fqdn => wstest02.int.m-box.de
hardwaremodel => x64
hostname => wstest02
is_virtual => false
kernel => windows
kernelmajversion => 6.3
operatingsystem => windows
operatingsystemmajrelease => 8
operatingsystemrelease => 8.1
os => {"name"=>"windows", "family"=>"windows", "release"=>{"major"=>"8", "minor"=>"1", "full"=>"8.1"}}
osfamily => windows
puppetversion => 3.8.1
rubyplatform => x64-mingw32
rubysitedir => C:/Program Files/Puppet Labs/Puppet/sys/ruby/lib/ruby/site_ruby/2.0.0
rubyversion => 2.0.0
system32 => C:\Windows\system32
virtual => physical
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by helge
close date 2015-07-09 12:32:07.518215

Comments

My bad - certainly functions are evaluated on the puppet master. Maybe there comes a time I will remember this in the first place. Using external YAML facts works fine for me.

helge gravatar imagehelge ( 2015-07-09 12:31:39 -0500 )edit

I reopen this again, I think loadyaml() is broken, though I cannot figure what it is since the code is trivial. Using following workaround I can at least load YAMLs form my manifest: $hash = parseyaml(file('mymodule/test.yaml'))

helge gravatar imagehelge ( 2015-07-11 06:00:58 -0500 )edit

Also, the manifest runs locally on windows and only acts up if compiled by my puppet master

helge gravatar imagehelge ( 2015-07-11 06:02:20 -0500 )edit