Ask Your Question
0

How can I dynamically load all subclasses of a class?

asked 2015-04-08 21:08:43 -0500

JohnsonEarls gravatar image

Hello,

I am just learning puppet, and of course I picked one of our harder server configurations to try to duplicate in puppet.

We have a DNS server that manages over 7000 DNS zones, and our use requires that we create and destroy DNS zones on a daily basis. Currently, we manage those zones as complete zone files in Subversion, and everyone is going in and editing the master named.conf file all the time. We don't like having lots of people messing around in the named.conf file because it has caused problems, and we want better controls over the content of the zone files.

I would like to use one of the various PuppetForge DNS modules to take care of this, but in order to make it manageable, I need to be able to keep each zone in one or more separate files, and have Puppet automagically find all those files and incorporate them into the configuration. Specifically, I do not want to require people to go in and edit some master class manifest to tell it to include their new dns zone manifest file.

I'm planning on creating a module called "dnsmaster" or something similar, and a "dnszone_files" subdirectory of that module's manifests directory which will be populated with the dnszone.pp manifest files for each dns zone. In an ideal world, I could do something like this:

init.pp:

class dns_master {
    # bring in the dns server, with configuration coming from hiera
    include dns::server
    # bring in all the zone files
    include dns_master::dns_zone_files::*
}

The only way I see it working right now is like this:

class dns_master {
    # bring in the dns server, with configuration coming from hiera
    include dns::server
    # bring in all the zone files
    include dns_master::dns_zone_files::customer1_com
    include dns_master::dns_zone_files::customer2_com
    include dns_master::dns_zone_files::customer3_com
    # ...
    include dns_master::dns_zone_files::customer376_com
    # ...
}

Even though this pattern is less likely to mess up than the central named.conf file, it's still a pain to make people modify this central file every time a new zone file gets created or removed.

is there any way to do something like my first example, using a wildcard or some other method to just pull in all the subclasses in that directory?

Thanks in advance, - Johnson Earls

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2015-04-09 04:16:23 -0500

pascal gravatar image

You can include arrays of classes, so you should be able to write a custom function to get all subclasses as an array and include that (i did not test this):

$zonefiles = get_zonefiles(dir)
include $zonefiles
edit flag offensive delete link more

Comments

This worked. I wrote a function "files_in_dir" (http://pastebin.com/Qqbbvbq4) then used this snippet to load the zone files: http://pastebin.com/EgXkiMfw .

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-09 21:44:14 -0500 )edit

What I missed yesterday: this will only add zone files, it gets slightly harder if you want to remove deleted files.

pascal gravatar imagepascal ( 2015-04-10 03:28:50 -0500 )edit

I'm willing to live with older db files still living on the dns server, as long as they're no longer referenced in the named.conf file. To get around that, we could just make our SOP for removing zones be: add an "ensure=>absent" in the definition of the zone file, and periodically clean old files.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-10 10:23:58 -0500 )edit
0

answered 2015-04-09 08:53:01 -0500

rnelson0 gravatar image

I use thias/bind for DNS. Check out my profile, hiera, and files. You could use a similar hash in your hiera setup and DNS admins could update a database of record that generates the yaml, plus have the zone files in version control.

The thias/bind module is fairly well fleshed out, you may need to submit PRs if it needs additional options. That is probably a better option than creating your own module and starting from scratch. I hope that helps.

edit flag offensive delete link more

Comments

This helps, but still has the "everyone has to update the same file" issue whenever DNS zones get added or removed. I was hoping to make it so DNS zone additions / deletions only need to affect the file that defines the DNS zone.

JohnsonEarls gravatar imageJohnsonEarls ( 2015-04-09 12:06:06 -0500 )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

Stats

Asked: 2015-04-08 21:08:43 -0500

Seen: 732 times

Last updated: Apr 09 '15