On Nov 9, 2:01 pm, Christopher Lee <chr...@spiralweb.com>
wrote:> Hello,
>
> I am trying to figure out a way to manage my network interfaces,
> specifically additional ip aliases on a single interface. We run RedHat.
> On many of our servers we need to bring up additional IP address on the
> same interface and create individual file ifcfg-eth0:1, ifcfg-eth0:2, etc.
> I found a good example of how to build a module to create the files:
>
> http://projects.puppetlabs.com/projects/1/wiki/Network_Interface_Temp...
>
> But the usage of this is to hard code values in a module calling the
> defined class with variables. I would like to move the variables external
> to the modules, either in the site.pp or some external_lookup or hiera
> file. I would need a way to loop through or call the class to build the
> file multiple times passing variables. I would like to not have to modify
> a module when a new interface is added.
>
> This is the first time I have tried to do anything like this in puppet, and
> I am just looking for examples or direction. Does this make since?
Judging from the examples and the actual requirements, you mean
"definition" or "defined type" where you say "defined
class". I
suppose that was just a typo, but the difference is significant and
essential, so be sure you understand it.
There are two basic techniques for declaring multiple resources whose
number, names, and / or parameters vary from node to node:
1) Resource title arrays
If you use an array as the title of a resource declaration then Puppet
interprets it as a declaration of one resource for each array element,
with the array elements as their titles. Example:
file { [''/tmp/foo'', ''/tmp/bar'']: ensure
=> present }
declares two File resources, File[''/tmp/foo''] and
File[''/tmp/bar''].
There are some important things to note here:
a) it works the same way when the title is specified as a variable
whose value is an array
b) each resource is declared with the same parameters, but
c) defined type instances are resources, too, and you can declare
multiples this way
Do not underestimate the significance of (c) above. Among other
things, you can use the $name local variable within a definition to
look up anything you like that may be specific to a particular
resource instance.
2) The create_resources() function
Create_resources() allows you to specify a hash of hashes of the
titles and all the (non-default) properties of any number of resources
of a given type, and it declares all the corresponding resources.
Read its documentation for more information. The only tricky part is
building up the necessary data structure, but hiera may be able to
help, or an inline template, or else you can always create a custom
function for that purpose.
You may find that those two approaches can be combined.
I suspect that much will depend on how rich the external data needs to
be, and the scope of its variability. I''d recommend you work that out
first.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.