2016-04-19 41 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)。