简体   繁体   English

列出厨师中所有声明的包

[英]List all the declared packages in chef

I'm working on a infrastructure where some servers don't have access to the internet , so I have to push the packages to the local repo before declaring them to be installed on Chef. 我正在一些服务器无法访问Internet的基础架构上工作,因此必须在声明将它们安装在Chef上之前将软件包推送到本地仓库。

However we've been on a situation where Chef failed to install a package since the package wasn't there on some boxes and it has been successful on some other boxes. 但是我们一直处于这样的情况,Chef无法安装软件包,因为某些盒子上没有该软件包,而在其他盒子上已经成功。

What I want to do is to run a Ruby/RSpec test before applying Chef config on the nodes to make sure the packages declared on the recipes do actually exist on the repo. 我想做的是在节点上应用Chef config之前运行Ruby / RSpec测试,以确保配方上声明的包确实在存储库中存在。

In order to do that I need to be able to list all the packages exists in the our recipes. 为此,我需要列出我们食谱中存在的所有包装。

My question is: Is there anyway to list all the declared packages in Chef? 我的问题是:总有没有列出Chef中所有已声明的软件包? I had a quick look at Chef::Platform and ChefSpec but unfortunately couldn't find anything useful to my problem. 我快速浏览了Chef :: PlatformChefSpec,但不幸的是找不到任何对我的问题有用的东西。

Do you have any idea where is the best place to look at? 您有什么想法的地方吗?

If you use ChefSpec you can find all the packages by calling chef_run.find_resources(:package) inside some test. 如果使用ChefSpec,则可以通过在某些测试中调用chef_run.find_resources(:package)来找到所有软件包。 See the source code . 参见源代码 Like this: 像这样:

require 'chefspec'

describe 'example::default' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

  it 'does something' do
    chef_run.find_resources(:package)...
  end
end

You could install one or more of the community ohai plugins . 您可以安装一个或多个社区ohai插件 For example the following will return information about installed sofware: 例如,以下内容将返回有关已安装软件的信息:

Once the plugins are enabled they will add additional node attributes that will be searchable from chef-server. 启用插件后,它们将添加其他节点属性,这些属性可从Chef-server中搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM