P5vc/ServerConfigurations

Some Anti Patterns here ...

Closed this issue · 5 comments

In this example, the hosts module for example has these if serverType == "webserver" do this else do that.
or the ufw module is running only if it's a database server

Wouldn't this example be more true to the FA design if it was using the roles to run the specific modules?

The other thing I am not sure I get is the initializers and the modules
let's take nginx, OK you install it via an initializer in WebServerInit
and the module keeps it's conf in sync through the template and running apply
but what will make nginx reload the configuration upon changes? How will it know something was changes in conf

P5vc commented

In this example, the hosts module for example has these if serverType == "webserver" do this else do that.
or the ufw module is running only if it's a database server

Wouldn't this example be more true to the FA design if it was using the roles to run the specific modules?

Yes, those modules are being run via roles. However, the problem is that sometimes overlap occurs. For example, we would like to customize the hosts file on all of our servers. For that reason, if you look in the roles directory, you will see that the "hosts" module is included in every single role. The problem, though, is that not every server type uses an identical host configuration. As such, we have two options:

  1. Create three different hosts modules designed for three different server types and then include each of those unique modules with the corresponding role
  2. Create one hosts module, and then use server-specific variables to choose which customized template to apply. We went with this option.

As for ufw, technically, we don't need the serverType check as it currently stands. However we plan to incorporate this module into other servers of different types in the future, therefore the serverType check is to future-proof the module for when we do.

The other thing I am not sure I get is the initializers and the modules
let's take nginx, OK you install it via an initializer in WebServerInit
and the module keeps it's conf in sync through the template and running apply
but what will make nginx reload the configuration upon changes? How will it know something was changes in conf

The short answer is nothing. You are correct that theoretically, if the server state does not change, nginx will not realize any changes made to its configuration. However, because we regularly do maintenance on our servers and reboot them, for our use case, nginx will eventually realize any changes made.

For someone else's use case, they may wish to include a check before writing the template to see if it differs from the current configuration, and if it does, then restart nginx after the new configuration is written.

P5vc commented

Here's an example where we do need to restart a service in order to force those changes to apply immediately:
https://github.com/P5vc/ServerConfigurations/blob/master/modules/postgresql/apply

P5vc commented

Because I haven't heard back, I'm going to assume we were able to answer your questions adequately and close this issue for now. However, if you have any more questions in the future, don't hesitate to re-open this issue or create a new one! :)

Thx for the detailed answer!