Ask Your Question
2

How do I make a function depend on declared resources?

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

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

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 = '255.255.255.0') {
  $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 ...
(more)
edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
3

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

Stefan gravatar image

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

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 (http://docs.puppetlabs.com/guides/custom_facts.html) 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

Comments

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 -0500 )edit

does the update help?

Stefan gravatar imageStefan ( 2013-04-26 03:24:27 -0500 )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 -0500 )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 -0500 )edit
1

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

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/iface.sh')
    File.open('/etc/iface.sh', 'w') do |file|
      file << "Removed for brevity"
    end
  end
  exec "/bin/bash /etc/iface.sh"
end

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

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

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

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
0

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

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

Stats

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

Seen: 304 times

Last updated: Apr 26 '13