0

I want to check all file having .war extension and move them to another folder in chef-client windows but it does not work.

if !Dir.glob("C:\\tempwar\\*.war").empty?  
    execute 'mv-war' do
        command 'move C:\tempwar\*.war C:\tomcat\webapps\ '  
    end
end
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Dao
  • 45
  • 4
  • [related](http://stackoverflow.com/questions/25980820/please-explain-compile-time-vs-run-time-in-chef-recipes) you're probably hit by the compile vs converge phases, when your ruby code run, there's no file in tempwar as it get executed at compile time. Be more explicit on what does not work, we can't guess what your problem is actually. – Tensibai Nov 04 '15 at 09:36

2 Answers2

0

The backslash characters here are not being interpreted as a pathname separator. Your \t becomes a tab character, for example, and \* is just a *. Double the backslashes or use a single-quoted string and you have a fighting chance.

cliffordheath
  • 2,536
  • 15
  • 16
0

It's always best to build paths in ruby with ::File.join. This takes care of the path separators in a platform neutral way. Also, it's prefered to use Chef conditionals rather than wrapping things in an if. So try this:

execute 'mv-war' do
  command "move #{::File.join('C:', 'tempwar', '*.war')} #{::File.join('C:',  'tomcat', 'webapps'} "
  only_if { Dir.glob(::File.join('C:', 'tempwar', '*.war').empty? }
end
Tejay Cardon
  • 4,193
  • 2
  • 16
  • 31