2017-05-04 57 views
1

我在主 - >代理模型中使用Puppet。我的清单存储在主服务器上,作为快速测试,我在代理上执行puppet agent -t以触发Puppet运行。木偶:如何执行一个类?

随着时间的推移,我的清单已经发展相当大的,我找只执行一个类说mycompany.someclass.class

我已经尝试了一些基于谷歌搜索的变化但没有工作的能力

 
puppet agent --tags mycompany.someclass.class 
puppet agent --tags "mycompany.someclass.class" 

puppet agent --tags Mycompany.Someclass.Class 
puppet agent -t --tags "Mycompany.Someclass.Class" 

puppet agent -t --tags Mycompany.Someclass.Class 
puppet agent --tags Mycompany.Someclass.Class 

puppet apply --tags mycompany.someclass.class 
puppet apply --tags Mycompany.Someclass.Class 

+1

你必须设置标签在类的作品前。 –

+0

就是这样;你能回答这个问题吗 ?这样我可以标记它的答案。 – bubbly

回答

1

您可以使用--tags参数执行资源子集,就像您在问题中提到的一样。但是,首先必须在要为该标记执行的资源中设置关联的标记。如果您只想执行一个类,则可以为该类设置一个标记,并将该标记指定为参数--tags以仅执行该类。

https://docs.puppet.com/puppet/4.10/lang_tags.html

在这种情况下,标签功能会比metaparameter对您有用得多。

https://docs.puppet.com/puppet/4.10/lang_tags.html#the-tag-function

# You can use the tag function inside a class definition or defined type to assign tags to the surrounding container and all of the resources it contains 
class myClass { 
    tag 'mytag' 
    ... 
} 

然后,您可以只执行myClass

# execute agent with tags 
puppet agent -t --tags mytag 

https://docs.puppet.com/puppet/4.10/lang_tags.html#restricting-catalog-runs