简体   繁体   English

Puppet - 如何将模块应用于puppet客户端节点?

[英]Puppet - how to apply module to puppet client node?

just starting with Puppet, really new to this world. 刚从Puppet开始,对这个世界来说真的很新。

I have 我有

  • CentOS 6 Puppet Master CentOS 6 Puppet Master
  • CentOS 6 Puppet Client CentOS 6 Puppet客户端

In Master have one module: 在Master中有一个模块:

 puppet module list
/etc/puppet/modules
âââ mstanislav-yum (v1.0.0)

So I want to apply same module to my puppet client but I can't or I don't know why 所以我想将相同的模块应用到我的木偶客户端,但我不能或我不知道为什么

root@puppetclient: puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for puppetclient
Info: Applying configuration version '1355737643'
Finished catalog run in 0.10 seconds

but there are not any changes to the client :-/ 但客户没有任何变化: - /

Any idea? 任何的想法?

You haven't declared the module (assigned it to your node) yet... 您还没有声明模块(将其分配给您的节点)...

Add this to site.pp: 将其添加到site.pp:

node 'fqdn of client' {
  include yum
} 

Then, you can run puppet agent -t to see it in action. 然后,您可以运行puppet agent -t来查看它的运行情况。

you can use the following command to view the details output 您可以使用以下命令查看详细信息输出

puppet agent --test --trace 木偶代理--test --trace

Try to use Hiera and yaml files, I think it is much more flexible and better organised. 尝试使用Hiera和yaml文件,我认为它更灵活,组织更好。

Edit the site.pp file: 编辑site.pp文件:

node "default" {
    hiera_include('classes')
}

After that you can call the classes in every of the specific node.yaml file with simple: 之后,您可以使用简单的方法调用每个特定node.yaml文件中的类:

classes:
  -class1
  -class2

I am using it on Ubuntu, works fine. 我在Ubuntu上使用它,工作正常。

You could try the --noop mode (dry run mode). 您可以尝试--noop模式(干运行模式)。

puppet agent --server=YOUR_PUPPET_SERVER_NAME --onetime --no-daemonize --verbose --noop

This would show up the changes that it should have done, but physically won't change anything. 这将显示它应该做的更改,但实际上不会改变任何东西。 Removing --noop will do all those changes. 删除--noop将执行所有这些更改。

Check the doc for explanation of other options in the above command. 检查doc以获取上述命令中其他选项的说明。 http://docs.puppetlabs.com/man/agent.html http://docs.puppetlabs.com/man/agent.html

The two main ways to apply a module to a node are to add one of the following to site.pp 将模块应用于节点的两种主要方法是向site.pp添加以下内容site.pp

node 'node <certname> (normally the fqdn)' {
    require <module name>
}

or 要么

node 'node's <certname>' {
    include <module name>
}

Then run in the node puppet agent --test 然后在节点puppet agent --test

require is like include but it creates dependency relationships and allows the same classes to declared more than once which is good if you want overlapping role classes. require就像include,但是它创建了依赖关系并允许多次声明相同的类,如果你想要重叠的角色类,这是很好的。

  1. First install the module from puppet forge 首先从puppet forge安装模块
  2. Open site.pp and add the following lines 打开site.pp并添加以下行
 node default { # include module_name include apache } 

Then run the following on you puppet agent. 然后在你的木偶代理上运行以下命令。

sudo puppet agent --test sudo木偶代理 - 测试

If you have added the node declaration in another location that isn't site.pp (which is the recommended way to do it) then remember to add the "import" config to site.pp which would reference the node manifest. 如果您在另一个不是site.pp的位置添加了节点声明(这是建议的方法),那么请记住将“import”配置添加到site.pp,它将引用节点清单。

This is how my config looks like. 这就是我的配置的样子。 Main manifest DIR with nodes DIR and site.pp file: 带有节点DIR和site.pp文件的主要清单DIR:

drwxr-xr-x. 3 root root 4096 May 19 07:23 nodes
-rw-r--r--. 1 root root   62 Jun  4 16:31 site.pp

This is the node declaration in my nodes DIR: 这是我的节点DIR中的节点声明:

node 'fqdn of client' {
  include yum
} 

Finally, site.pp in the main manifest DIR would import the node as follow: 最后,主清单DIR中的site.pp将导入节点,如下所示:

import 'nodes/*.pp'

node default { }

您必须创建一个节点定义,其中包含要应用的类的“包含”。

Run

puppet apply -e "include mstanislav-yum"

if you want to run the module on its own, though it is more usual to include a node definition in your site.pp manifest. 如果你想自己运行模块,虽然在你的site.pp清单中包含一个节点定义更常见。

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

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