Ask Your Question
0

Notify an ordered of resources

asked 2018-12-21 09:15:33 -0600

mazdajai gravatar image

updated 2018-12-21 09:16:03 -0600

I have a list resources that I would like to call in order with notify. Knowing that puppet execute them in un-order, how do I chain it properly? https://puppet.com/docs/puppet/4.10/l...

concat { $zone_file_stage:
  owner   => $dns::server::params::owner,
  group   => $dns::server::params::group,
  mode    => '0644',
  replace => $zone_replace,
  require => Class['dns::server'],
  notify  => Exec[
    "bump-${zone}-serial",
    "freeze-${zone}",
    "thaw-${zone}",
  ]
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-12-21 11:33:26 -0600

You do not “call” resources. Resources are _applied_, but not executed or anything like that.

With the require and notify meta-parameters you've already ordered your resources like that:

Class['dns::server'] -> Concat[$zone_file_stage]

Concat[$zone_file_stage] ~> Exec["bump-${zone}-serial"]
Concat[$zone_file_stage] ~> Exec["freeze-${zone}"]
Concat[$zone_file_stage] ~> Exec["thaw-${zone}"]

As you've already acknowledged, the last three ordering rules are independent. It is possible that the thaw… exec is applied before the bump or freeze exec resource.

You probably want to drop the notify parameter entirely and specify a chain rule statement instead, like:

Concat[$zone_file_stage] ~> Exec["bump-${zone}-serial"]
  ~> Exec["freeze-${zone}"] ~> Exec["thaw-${zone}"]

Assuming all your exec resources are refreshonly, only if Concat[$zone_file_stage] has caused a change on the target system, any following exec resource is applied. Only if bump… has caused a change, freeze… and thaw… are applied. Only if freeze… has caused a change, thaw… is applied. (Of course your resource could be notified from somewhere else [e.g. via some resource collector]).


As the language style guide suggests be parsimonious with the chaining arrows. If you're in a defined type definition, where all resource you mentioned are defined, I'd write:

define foo::bar_zone (
  String[1] $zone_file_stage,
  …
) {
  $zone = $title

  …

  concat { $zone_file_stage:
    …
    notify  => Exec["bump-${zone}-serial"],
  }

  exec { "bump-${zone}-serial":
    …
    notify => Exec["freeze-${zone}"],
  }

  exec { "freeze-${zone}":
    …
    notify => Exec["thaw-${zone}"],
  }

  exec { "thaw-${zone}":
    …
  }
}
edit flag offensive delete link more

Comments

Thanks Kai! I was trying to avoid the excessive use of the chaining arrows. It makes sense now.

mazdajai gravatar imagemazdajai ( 2018-12-21 14:54:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-12-21 09:15:33 -0600

Seen: 73 times

Last updated: Dec 21