2

I have several modules which uses the same admin mail, right now it's hardcoded all over the place, is it correct to setup a global variable, I mean, with global scope or is there something else I can do to accomplish this?

2

That seems like a pretty reasonable use case for a global variable.

Be careful of a situation where you'd want to customize it for specific systems or modules - passing it as a class parameter (or using Hiera, which you should!) to classes that use it (instead of referencing the top scope variable from within classes) is a good way to leave yourself some flexibility.

2
  • so a variable for global scope is ok then? I was afraid that it was too dirty... – poz2k4444 Mar 31 '14 at 1:40
  • @poz2k4444 If that will always be the same thing, then yeah - I'd say referencing a top scope variable is just fine. You may want to build in the flexibility of parameterizing its use in classes, though, just in case. – Shane Madden Mar 31 '14 at 1:42
4

I would stick that value in hiera (as 'adminmail' or whatever) so that you could later vary it if needed. Parameterizing it where it's used (like Shane said) is a good idea as well.

1
  • Seconded - hiera is very useful since you could e.g. decide to have one mail address for dev and test environments, and another for production. It takes some time to figure it out but is well worth it. – Jenny D Mar 31 '14 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.