2016-04-19 202 views
1

我使用的是廚師下載war文件到從nexus.The配方文件夾獲得Nexus下載神器如下廚師 - 使用remote_file資源

remote_file '/home/Test/AAA.war' do  
    source 'https://IP.com:8082/ URL Of the Repo/AAA.war'  
    owner 'root'  
    group 'root'  
    mode '0755' 
    action :create 
    end 

但是如果我運行這個配方,我得到未經授權的訪問錯誤

是否需要爲nexus登錄提供用戶名和密碼?

我應該寫一個批處理腳本從nexus而不是配方下載嗎?

+0

Riotgames [神器](https://github.com/RiotGamesCookbooks/artifact-cookbook)cookbook可以作爲靈感的幫助(根據我所知,不再維護)。特別是從nexus部分下載[這裏](https://github.com/RiotGamesCookbooks/artifact-cookbook/blob/master/libraries/chef_artifact_nexus.rb)以及他們的nexus CLI gem [here](https:// github。 com/RiotGamesMinions/nexus_cli) – Tensibai

回答

2

我將驗證您的Nexus服務器是否需要身份驗證才能下載任何文件的第一種方法。我會在隱身模式下打開瀏覽器並轉到remote_file資源的source媒體資源的網址。我期待它給你一個「未經授權的訪問錯誤」的登錄頁面。這將確認您的問題,即必須爲Nexus登錄名提供用戶名和密碼。

爲此,您可以使用remote_file資源的header屬性將必要的憑據傳遞給Nexus服務器。

有關詳細信息,請點擊這裏。 https://docs.chef.io/resource_remote_file.html#properties

我不明白Nexus的登錄方法,但它可能看起來像來自文檔頁面的示例。 headers("Authorization"=>"BasiC#{ Base64.encode64("#{username}:#{password}").gsub("\n", "") }")

+4

你也可以把它放在正常的網址中。 '的https://用戶名:密碼@主機/ path'。 – coderanger

0

這就是我所做的(基於Coderanger答案)。

nodejs_url = node['ci_cd']['ubu_nodejs_url'] 
... 

remote_file nodejs_path do                       
    source nodejs_url.gsub(/(https?:\/{2})/, '%s%s:%[email protected]' % ['\1', artifactory_user, artifactory_pass])   
    checksum nodejs_url_checksum                    
    owner 'root'                        
    group 'root'                        
    mode  '0644'                        
    notifies :install, 'dpkg_package[nodejs]', :immediately              
    not_if { ::File.exists?(nodejs_path) }                    
end 

dpkg_package 'nodejs' do                        
    source nodejs_path                        
    action :nothing                         
end 

在這個例子中,我創建remote_filedpkg_package之間的依賴關係只是在一個地方管理後衛(not_if)。