Hi,
there are some minor not-best-practices in your code:
1. create_resource
I prefer using lambda over create_resources as these allows explizit resource
declaration which are then bound to the class.
This gives you explizit ordering, which you must add if using create_resource.
2. explizit lookups
you are doing explizit lookups. I prefer parameters using automatic databinding
3. accessing facts
Using $::factname is not the most modern way. Migrate to using facts hash
(facts is a protected variable).
e.g. $facts['collect']
Your new code could be the following:
class mymodule (
Hash $external_http_domains, # not providing a default means
that you must deliver data.
Optional[Hash] $internal_http_domains = undef, # if you want to allow undef
values, you can set the data type to optional.
Hash $http_defaults,
){
if $facts['collect'] == 'external' {
$external_http_domain.each |$key, $value| {
nginx::resource::server { $key:
* => $value + $http_defaults,
}
}
} else {
$internal_http_domains.each |$key, $value| {
nginx::resource::server { $key:
* => $value + $http_defaults,
}
}
}
}
hth,
Martin
> On 6. Feb 2021, at 14:34, Nerbolff <[email protected]> wrote:
>
> hello there,
>
> I would like to clean up my puppet recipes.
> My init.pp. I have ~three_hundred entries as 'new resources'(see below).
> here is how is setup today. I am wondering if we could do better. I am
> working with puppet v5.
>
> ideas or suggestions? thank you very much.
>
>
> mymodule/manifests/init.pp
> class mymodule {
>
> if ($::collect == 'external') {
> create_resources('nginx::resource::server',
> lookup('mymodule::external_http_domains'), lookup('mymodule::http_defaults'))
> ...
> ...
> ...
> } else {
> create_resources('nginx::resource::server',
> lookup('mymodule::internal_http_domains'), lookup('mymodule::http_defaults'))
> ...
> ...
> ...
> }
>
>
> mymodule/data/external.yaml
> mymodule::http_defaults:
> ensure: present
> ssl: true
> listen_port: 443
> ...
> ...
> ...
> mymodule::external_http_domains:
> order1.internet.com:
> use_default_location: false
> ssl_cert: /etc/nginx/ssl/twe/order1.internet.com.pem
> ssl_key: /etc/nginx/ssl/twe/order1.internet.com.key
> ...
> ...
> ...
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/1124d0d6-06b4-4ad5-9f06-a8a30fb9bbbfn%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/07F7BA4F-8EA5-44B4-A741-D03D6741DC6C%40gmail.com.