windows - Cannot access remote files with puppet -


i can not seem puppet happily grab file network share

    file { "installerfile":         ensure => file,         source => '\\drivename\installer.msi',         path   => 'c:/puppetstuff/installer.msi',     } 

fails bad uri error. says drive name bad hostname:

debug: reraising failed convert '/installer.msi' uri: bad component(expected host component): drivename 

how can access network share?

after digging in puppet/util have found need escape each slash when using single quotes:

source => '\\drivename\installer.msi' 

should be

source => '\\\\drivename\\installer.msi' 

messy irb output below:

1.9.3-p547 :036 > path = '\\\\drivename\test'  => "\\\\drivename\\test" 1.9.3-p547 :037 > puts path \\drivename\test  => nil 1.9.3-p547 :038 >     params = { :scheme => 'file' }  => {:scheme=>"file"} 1.9.3-p547 :039 >  path = path.gsub(/\\/, '/')  => "//drivename/test" 1.9.3-p547 :040 > 1.9.3-p547 :041 >         if unc = /^\/\/([^\/]+)(\/.+)/.match(path) 1.9.3-p547 :042?>           params[:host] = unc[1] 1.9.3-p547 :043?>           path = unc[2] 1.9.3-p547 :044?>         elsif path =~ /^[a-z]:\//i 1.9.3-p547 :045?>           path = '/' + path 1.9.3-p547 :046?>         end  => "/test" 1.9.3-p547 :047 > params[:path] = uri.escape(path)  => "/test" 1.9.3-p547 :048 > params  => {:scheme=>"file", :host=>"drivename", :path=>"/test"} 1.9.3-p547 :049 > uri::generic.build(params)  => #<uri::generic:0x007f8da327e808 url:file://drivename/test> 1.9.3-p547 :050 > uri::generic.build(params).host  => "drivename" 1.9.3-p547 :051 > uri::generic.build(params).path  => "/test" 

you safer using unix style paths in case. puppet/util converts unc path unix style path anyway.

# convert path file uri def path_to_uri(path)   return unless path   params = { :scheme => 'file' }   if puppet.features.microsoft_windows?     path = path.gsub(/\\/, '/')     if unc = /^\/\/([^\/]+)(\/.+)/.match(path)       params[:host] = unc[1]       path = unc[2]     elsif path =~ /^[a-z]:\//i       path = '/' + path     end   end   params[:path] = uri.escape(path)   begin     uri::generic.build(params)   rescue => detail     raise puppet::error, "failed convert '#{path}' uri: #{detail}"   end end 

so source => '//drivename/installer.msi safer method avoid escaping issues.

hope helps.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -