Puppet: relationship between resources on different nodes

喜欢而已 提交于 2019-12-05 09:51:49

In a distributed "puppet" setup, the apply order isn't guaranteed.

Puppet don't do orchestration across multiple nodes. At best, your changes will get applied multiple times on the machines and finally will converge to the desired state.

Dependencies only work in a same node. You can actually get values of resources exported by others nodes (for eg to configure the firewall of your db to allow the web server to do sql) Or cheat with hiera to know who have the "db" and "app" roles.

For orchestration see tools like mcollective, capistrano, ansible,...

Whenever a resource depends on another resource, use the before or require metaparameter or chain the resources with ->. Whenever a resource needs to refresh when another resource changes, use the notify or subscribe metaparameter or chain the resources with ~>. Some resources will autorequire other resources if they see them, which can save you some effort.

Refer to link for more precision.

In init.pp where you declare/instantiate these classes, replace the include statements with parameterized class syntax:

class {"taskname":} -> class {"taskname2":}
This will ensure taskname is invoked before taskname2.

Check link

A bit of googling for puppet node dependency turns up some links about exported resources, which seems like the way to go.

According to http://docs.puppetlabs.com/puppet/latest/reference/lang_exported.html

Exported resources allow nodes to share information with each other.

Basically you export a resource in the node which it belongs to, and collect it in the node that requires it and use dependency arrows as usual.

MCollective also appears to be an alternative, but seems to be a whole new framework.

You can't do that just using Puppet. Conceptually, with Puppet you generate a static description of a node configuration, and then you apply it. The exported resources system is convenient, but doesn't fundamentally changes the way Puppet works (you can convince yourself by noticing you could just hardcode the resources, and this would have the exact same effect).

For this reason, you need another kind of orchestration system, and you should not set enable => running on your services.

Unfortunately, I do not have great recommendations :

  • I only used heartbeat, which in my experience was hard to configure, unreliable, and very limited (only a handful of nodes are supported).
  • Ubuntu has a juju tool that does exactly what you want and seems easy to use, but I have no experience with it.
  • There is probably something equivalent in your distribution of choice.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!