How do I check if a folder exists in Chef?

前端 未结 2 413
粉色の甜心
粉色の甜心 2021-02-03 10:18

This is my code:

if !::File.exist?(\"#{node[\'iis\'][\'home\']}\\\\backup\\\\BkpB4Chef\")
 windows_batch \"Backup IIS Config\" do
  code <<-EOH
   \"#{node         


        
2条回答
  •  梦毁少年i
    2021-02-03 10:51

    Use Dir.exists?. You can also replace if ! condition by unless condition which reads a bit better.

    unless Dir.exist? "#{node['iis']['home']}\\backup\\BkpB4Chef"
     windows_batch "Backup IIS Config" do
      code <<-EOH
       "#{node['iis']['home']}"\\appcmd add backup BkpB4Chef
      EOH
     end
    end
    

提交回复
热议问题