本文介绍了如何在Puppet中迭代已定义类型的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历所有已定义类型的实例(例如Apache :: Vhost)。但是,此循环仅列出我在该范围内的资源。

I want to iterate over all instances of defined types (ex. Apache::Vhost). However this loop only list my resources under the scope.

<% scope.catalog.vertices.each do |resource| -%>
<%# if resource.type == "Apache::Vhost" -%>
#Include <%= resource.title %>
<% end -%>


推荐答案

在编译时遍历目录durig(目录构建是个坏主意。

Walking the catalog durig at compile time ("catalog building") is a Bad Idea.

如果您确实想要此功能,请考虑将迭代代码移至,它将生成与您的主模板目前所尝试的内容相似的文件内容。

If you really want this functionality, think about moving the iteration code to a custom provider that will generate the file content akin to what your master side template tries at the moment.

在同步阶段,您可以通过 self.resource.catalog 安全地访问完整目录。

At the sync stage, you can safely access the complete catalog via self.resource.catalog.

这篇关于如何在Puppet中迭代已定义类型的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 09:14