0

How to overwrite defined type in nodes.pp? I want to able to set custom domain using nodes.pp. Case Default isn't an option.

I'm using puppet 6.0..

The following method doesn't work. It says Could not find declared class resolv::resolv_config. It looks like it used to work in 3.0 according to this answer.

nodes.pp

node "test001" {
  class { 'resolv::resolv_config':
    domain => "something.local",
  }
}

modules/resolv/manifests/init.pp

class resolv {
    case $hostname {
        /^[Abc][Xyz]/: {
            resolv:resolv_config { 'US':
                domain => "mydomain.local",
            }
        }
    }
}

define resolv::resolv_config($domain){
    file { '/etc/resolv.conf':
        content => template("resolv/resolv.conf.erb"),
    }
}

resolv.conf.erb

domain <%= @domain %>
user630702
  • 2,529
  • 5
  • 35
  • 98

1 Answers1

1

There are a couple of problems here, but the one causing the "could not find declared class" error is that you are using the wrong syntax for declaring a defined type. Your code should be something like this:

node "test001" {
  resolv::resolv_config { 'something.local':
    domain => "something.local",
  }
}

There are examples of declaring defined types in the documentation, https://puppet.com/docs/puppet/latest/lang_defined_types.html.

Once you get that working, you'll find another problem, in that this definition

define resolv::resolv_config($domain){
    file { '/etc/resolv.conf':
        content => template("resolv/resolv.conf.erb"),
    }
}

will cause a error if you try to declare more than one resolv::resolv_config, because they will both try to declare the /etc/resolv.conf file resource. You almost certainly wanted to use a file_line resource.

Jon
  • 3,573
  • 2
  • 17
  • 24