Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet: What's the difference between an ordering arrow and a notification arrow?

Tags:

puppet

In the official Puppet docs it says that there are two chaining arrows: https://docs.puppetlabs.com/puppet/latest/reference/lang_relationships.html

-> (ordering arrow) Causes the resource on the left to be applied before the resource on the right. Written with a hyphen and a greater-than sign.

~> (notification arrow) Causes the resource on the left to be applied first, and sends a refresh event to the resource on the right if the left resource changes. Written with a tilde and a greater-than sign.

Can someone clarify the difference between these two?

like image 310
Peter Smit Avatar asked Jan 06 '15 16:01

Peter Smit


1 Answers

The document you mentioned has given the best explanation. If you try to understand it by simple way, using the exist sample.

Package['ntp'] -> File['/etc/ntp.conf'] ~> Service['ntpd']

For File['/etc/ntp.conf'], puppet needs to make sure that the package ntp has been installed before it creates or updates the file ntp.conf. There is no restart request.

But for Service['ntpd'], ntp.conf needs to exist first - that's the same order as ->. * But if puppet finds the file ntp.conf has any changes (whether it is created or updated), service ntp needs to be restarted. That's the difference*.

For more reading about ordering in puppet, please see these documents:

Learning Puppet — Resource Ordering

And do some testing by yourself to understand how it works.

  1. set Package['ntp'], File['/etc/ntp.conf'] ,Service['ntpd'] with the order.
  2. run puppet apply to make sure, Package/File/Service are ready on the system.
  3. make a change in the file ntp.conf.
  4. enable the --debug option with the puppet apply command. The debug log will give you detail in the background - for example, you should see that the file gets updated and the ntpd service gets restarted.
like image 61
BMW Avatar answered Oct 01 '22 02:10

BMW