On 2018-10-08 08:44, Eirik Øverby wrote:
> Hi,
>
> Sorry for hijacking this thread, but it caught my interest.
>
> My scenario is that I'd like to re-use the title of an nginx server instance in, say, the log file for that server instance. However, since I don't want to touch the nginx module itself, it seems I have to wrap its server class in one of my own to allow setting this kind of defaults - but I have found no way to use $title in this way.
>
> The best would be if I could do something like this - assuming nginx::server is a module class already defined:
> nginx::server {
> default:
> $access_log => "${nginx::logdir}/${mytitle}.log",
> ...,
> ;
> 'my-fine-443-server':
> listen_port => 443,
> ;
> }
>
> Here it would also be helpful if I could somehow re-use the default values in the individual instances too - I might not know what the default values are, but I would know what to do with them (append '.log' for instance, or set listen_port to the same value as ssl_port or vice versa).
>
> Even being able to do the following would be better than what we're currently doing, which is repeating the fully-typed access log line (and all the other similar entries) for every instance:
> nginx::server { 'my-fine-443-server':
> $access_log => "${nginx::logdir}/${mytitle}.log",
> listen_port => 443,
> }
>
> Not sure how I could use functions here either, as I want this to happen at instantiation time, not in the module itself.
>
> Am I hoping for too much? Missed something?
>
I have a bit of a hard time following this. You say assuming
"nginx::server" is a class, but then it looks like it is a resource
since it is instantiated with a title. Also don't understand what
$mytitle is - is that supposed to be $title ?
(so, having complained ;-) some more perhaps useful tips follows...)
If you configure defaults for what you are wrapping via hiera, you can
lookup the defaults in your wrapper.
If you want to assign multiple things at once. Here is an example:
class original($foo, $bar, $etc) { }
class { 'original':
foo => 10,
bar => 20,
etc => 30,
}
// multi-assign from declared class, assigns all variables on the left
// from the class - variables must exist in the class or an error is
// raised
[$foo, $bar, $etc] = Class['original']
notice "${foo}, ${bar}, ${etc}"
There are tickets with a feature request to be able to say things like
"my class takes the exact same parameters as some other class". We do
not have an idea for what that would look like at this point. There is a
Like[T] data type in the process of being added, but it would need to
(very tediously) be repeated for every parameter. New syntax in the
language would be needed to support this a better way (i.e. very long
fuse on that...)
Best advice; be explicit about defaults, and get them via hiera and use APL.
Hope something of this is of value.
Best,
- henrik