Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active August 29, 2015 14:23
Show Gist options
  • Save spuder/f1eeecc65b2b8245258e to your computer and use it in GitHub Desktop.
Save spuder/f1eeecc65b2b8245258e to your computer and use it in GitHub Desktop.
Chef helper win_friendly_path
# Notice how log_dir starts with the correct two slashes?
# By the time it is inserted into the template, one of those slashes is removed.
# Trying to use win_friendly_path to undo that
default['iis']['log_dir'] = 'F:\\LogFiles'
================================================================================
Recipe Compile Error in c:/chef/cache/cookbooks/nd-web/recipes/default.rb
================================================================================
NoMethodError
-------------
undefined method `win_friendly_path' for Chef::Resource::Template
Cookbook Trace:
---------------
c:/chef/cache/cookbooks/nd-web/recipes/config_files.rb:138:in `block in from_file'
c:/chef/cache/cookbooks/nd-web/recipes/config_files.rb:135:in `from_file'
c:/chef/cache/cookbooks/nd-web/recipes/default.rb:29:in `from_file'
Relevant File Content:
----------------------
c:/chef/cache/cookbooks/nd-web/recipes/config_files.rb:
::Chef::Recipe.send(:include, Windows::Helper)
template "foo.json" do
source 'foo.json.erb'
variables(
:log_dir => win_friendly_path( node['iis']['log_dir'] )
)
action :create
end
@spuder
Copy link
Author

spuder commented Jun 30, 2015

It appears that you can't call helper methods inside of the variables function.

Splitting it out fixes the error, but still doesn't give a windows safe path.

::Chef::Recipe.send(:include, Windows::Helper)
log_dir = win_friendly_path( node['iis']['log_dir'] )

template "foo.json" do
  source 'foo.json.erb'
  variables(
    :log_dir  => log_dir
  )
  action :create
end

No error, but the path is still

F:\foo\bar

Not

F:\\foo\\bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment