Ask Your Question

How do I make a function depend on declared resources?

asked 2013-04-25 07:17:36 -0600

updated 2013-04-26 14:02:34 -0600

I have defined a type vlan::network for configuring a network interface based on captured Cisco Discovery Protocol frames.

Since capturing these frames takes a while, the idea was to run this capture one and store it in a YAML file.

The defined type looks like this:

define vlan::network ($vlan = $title, $ipaddress, $gateway = undef, $netmask = '') {
  $iface = get_interface_vlan($vlan, '/etc/iface.yml')

  if is_array($iface) {
    network::bond::static { "bond${vlan}":
      netmask   => $netmask,
      ipaddress => $ipaddress,
      ensure    => up;

    netslave { $iface: master => "bond${vlan}" }
  } else {
    network::if::static { $iface:
      netmask    => $netmask,
      ipaddress  => $ipaddress,
      macaddress => getvar("::macaddress_${iface}"),
      ensure     => up ...
edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted

answered 2013-04-25 15:17:28 -0600

Stefan gravatar image

updated 2013-04-26 03:24:05 -0600

The problem here is that the get_interface_vlan function runs on your master during the compilation of the catalog. This will not work in the way you intended because:

  • functions will always run before the compiled catalog is applied and therefore will always run before your exec resource - this is by design
  • functions will always run on your puppet master - which is probably not what you want anyways

One possible solution is to create custom facts ( for the interesting attributes (have a look at facter/interfaces.rb as an example on how to dynamically ... (more)

edit flag offensive delete link more


Stefan, seems you're right. The main problem is that the function is called too early. I use Puppet standalone using puppet apply, but still the problem is that the ...(more)

Asgeir gravatar imageAsgeir ( 2013-04-26 02:52:49 -0600 )edit

does the update help?

Stefan gravatar imageStefan ( 2013-04-26 03:24:27 -0600 )edit

Stefan, thanks, this helps in clarifying my understanding. Apart from custom facts -- would a custom type or provider be executed on the master or the agent?

Asgeir gravatar imageAsgeir ( 2013-04-26 06:21:52 -0600 )edit

The input validation of a custom type and setting possible default values when omitting a parameter in your manifest happens on the master. Everything else is executed on the agent.

Stefan gravatar imageStefan ( 2013-04-26 14:48:40 -0600 )edit

answered 2013-04-26 14:07:19 -0600

As Stefan pointed out, the problem is that the function is called at the parsing stage, and on the Puppet master.

The way I solved this was by way of custom facts, and having the function extract the information from the custom fact.

The custom fact looks like this:

require 'yaml'

if not File.exists?('/etc/iface.yml')
  if not File.exists?('/etc/')'/etc/', 'w') do |file|
      file << "Removed for brevity"
  exec "/bin/bash /etc/"

vlans = YAML::load('/etc/iface.yml'))

vlans.each do |vlan,ifaces|
  Facter ...
edit flag offensive delete link more

answered 2013-04-25 10:28:01 -0600

Ancillas gravatar image

Is it a scoping issue? What happens if you declare your relationships higher up than the vlan class, say in the class or node definition where you call include vlan?

edit flag offensive delete link more

answered 2013-04-25 14:36:15 -0600

lavaman gravatar image

Have all the resources in your defined type require that exec. Should solve your problem.

edit flag offensive delete link more

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


Asked: 2013-04-25 07:17:36 -0600

Seen: 323 times

Last updated: Apr 26 '13