Last active
August 29, 2015 14:23
-
-
Save spuder/f1eeecc65b2b8245258e to your computer and use it in GitHub Desktop.
Chef helper win_friendly_path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
================================================================================ | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::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 |
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
https://www.chef.io/blog/2014/03/12/writing-libraries-in-chef-cookbooks/
http://dougireton.com/blog/2012/12/16/how-to-include-the-windows-cookbook-helper-methods-in-your-chef-recipe/