I'll preface this by saying that I know a little Ruby but not very well, so this may well be a common Ruby mistake (but I can't seem to find an answer!)
I have this Chef recipe (run using Vagrant):
package "php5-fpm" do
action :install
end
template "/etc/php5-fpm/pool.d/site" do
source "php-fpm.erb"
owner "root"
group "root"
mode 0644
action :create
only_if "dpkg --get-selections | grep php5-fpm"
end
service "php5-fpm" do
action :restart
end
This fails with the following message:
================================================================================
Recipe Compile Error in /tmp/.../cookbooks/site/recipes/php-fpm.rb
================================================================================
SyntaxError
-----------
compile error
/tmp/.../cookbooks/site/recipes/php-fpm.rb:1: syntax error, unexpected
tIDENTIFIER, expecting $end
template "/etc/php5-fpm/pool.d/site" d...
^
Cookbook Trace:
---------------
/tmp/.../cookbooks/dosos/recipes/php-fpm.rb:1:in `from_file'
Relevant File Content:
----------------------
/tmp/.../cookbooks/dosos/recipes/php-fpm.rb:
end 2: :restart" do-selections | grep php5-fpm"
This doesn't make a lot of sense to me because the "relevant file content" appears to be munged from different parts of the file.
Is there something Ruby has about putting forward slashes in strings (and if so, why not error on the preceding 3 slashes, unless it's running right-to-left?)
I was using Vagrant to provision my server using the Chef scripts. The Chef scripts were edited on Windows, which were available on the Linux VM via a shared folder.
The mistake was that my editor on Windows was not configured to use Unix line-endings, which confused Ruby. Stripping carriage returns (^M
) allowed the script to run normally.