Ask Your Question
0

track changes create_resources PE 2015.3.2

asked 2016-03-10 01:36:20 -0500

FranzCC gravatar image

Hi,
i don't find a way howto track changes on create_resources.
Normally i would use the refreshonly after the create resources,
but i have to track what resource did change.
E.g.:

class networkinterfaces {
$interfaces = hiera_hash('test::interfaces')
create_resources(network, $interfaces)
}

How can i track what interface changed and to something like a sub() ?

Rgds.

Franz

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-03-11 04:18:49 -0500

FranzCC gravatar image

updated 2016-03-18 02:07:52 -0500

Hi Alex,
When testing your solution (using the defaults as exec), i cannot get the acutal interface that changed
The variable ${name} has the value main.
I need the item name like in the has e.g. eth0. If eth0 changes, i want to exec with a specific parameter to track changed and react to it.
If it's not possible, than i have to trigger an action for all interfaces, and that's not the way to go.
Perhaps there's an other solution.

Rgds.

Franz

Details:

Hiera snip: (3 interfaces)

  "network": {
    "eth0": {
      "ensure": "present",
      "netmask": "255.255.255.0",
      "method": "static",
      "family": "inet",
      "ipaddress": "192.168.0.100",
      "onboot": "true",
      "options": [
        {
          "gateway": "192.168.0.1",
          "dns-search": "test.com",
          "dns-nameserver": [
            "10.10.10.10",
            "10.10.10.11"
          ]
        }
      ],
      "mode": "raw"
    },
    "eth1": {
      "ensure": "present",
      "netmask": "255.255.255.0",
      "method": "static",
      "family": "inet",
      "ipaddress": "192.168.10.100",
      "onboot": "true",
      "mode": "raw"
    },
    "eth2": {
      "ensure": "present",
      "netmask": "255.255.255.0",
      "method": "static",
      "family": "inet",
      "ipaddress": "192.168.100.100",
      "onboot": "true",
      "mode": "raw"

Class:

class network {
  $interfaces = hiera_hash('network')
  create_resources(network_config, $interfaces)
}

For all three interfaces there are seperate systemd script (ifup@[interfacename]) E.g: if i change the hiera config for eth0 i only want to run my ifup@eth0 script.

How can this be done correctly ?

Code:

 define dolinks {

    file { "/etc/systemd/system/multi-user.target.wants/ifup@$name.service":
      ensure => link,
      target => "/lib/systemd/system/ifup@.service",
    }
}

define dorestart {

   exec {"restart_service_$name":
      command => "/usr/sbin/service ifup@$name restart",
      refreshonly => true,
}

}

$ifnames = hiera_hash('network')

$interfaceKeys = keys($ifnames)

dolinks{$interfaceKeys:}

create_resources(network_config, $ifnames, notify =>  { dorestart{$interfaceKeys:} })

Update: The proposed solution works !

edit flag offensive delete link more

Comments

It's not clear from your post what you're trying to do. You'll need to update showing all of the relevant code, including your network defined type and the exec that you want refreshed, also explain clearly what you're trying to do.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-11 05:43:48 -0500 )edit

Hi Alex, actually it's quite simple. I have 3 interfaces to configure. If one change, i only want to reload the networkconfig of the particular interface. Ever interface has a corresponding systemd script. I think, create_resources cannot tell, what interface changed and representing it as varaible?

FranzCC gravatar imageFranzCC ( 2016-03-14 01:26:15 -0500 )edit

As I said, I need to see the code.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-14 01:50:19 -0500 )edit

Hi Alex, i updated my answer with a code snpippet. It should be clear now. Thx. Franz

FranzCC gravatar imageFranzCC ( 2016-03-14 02:38:32 -0500 )edit

Thanks, but what is a 'network'? A type you defined somewhere? Is it from a Puppet Forge module?

Alex Harvey gravatar imageAlex Harvey ( 2016-03-14 03:30:44 -0500 )edit
0

answered 2016-03-10 21:38:02 -0500

updated 2016-03-15 08:32:07 -0500

If I understand you correctly I think you need something like this:

class networkinterfaces {
  $interfaces = hiera_hash('test::interfaces')
  create_resources(network, $interfaces, { notify => Exec['your_exec'] })
}

And then somewhere else:

exec { 'your_exec':
  refreshonly => true,
  ...
}

Update

OK, now that I see your code, I think what you need is

class networkinterfaces {
  $interfaces = hiera_hash('test::interfaces')
  create_resources(network, $interfaces)
}

And

define dorestart {
   exec {"restart_service_$name":
      command     => "/usr/sbin/service ifup@$name restart",
      refreshonly => true,
      subscribe   => Network_config[$name],
   } 
}
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: 2016-03-10 01:36:20 -0500

Seen: 142 times

Last updated: Mar 18 '16