P5vc / fetch-apply

Transparent Server Configuration and Management
MIT License
17 stars 3 forks source link

Explicit mapping of hosts to classes #3

Closed emmetog closed 3 years ago

emmetog commented 3 years ago

From the README:

Because each webserver's hostname contains webserver somewhere within it, and each database server's hostname contains database somewhere within it, yet no webserver's hostname contains database within it and no database server's hostname contains webserver within it, Fetch Apply will automatically identify and associate each server with its correct class.

Is it possible to explicitly manage the mapping between hosts and classes instead?

My use case is that my hostnames don't always follow a pattern and in some cases the hostnames are not even controlled by me, they are imposed upon me. For this reason I'm not going to be able to rely on using a naming convention to map between hostnames and classes. My only option is to do it explicitly.

For reference, ansible does this in an "inventory" file which ends up looking something like this (they use yml):

[databases]
db01.mydomain.com
ws01.test.mydomain.com
db02.mydomain.com

Could fetchapply allow a similar explicit mapping? If so, I'd likely also need a configuration option in /etc/fetchapply to disable pattern mapping of hosts to classes, just to avoid unexpected surprises.

emmetog commented 3 years ago

To give the most flexibility, ideally it would also be possible for a host to have multiple classes, for example if I have a separate webserver and database in production but in test I want the same server to act as both. Does the current implementation of fetchapply allow hosts to have multiple classes?

P5vc commented 3 years ago

Thank you for this suggestion. You raise a valid point, and I agree that a "manual override" of the direct hostname-to-class association would be a useful feature, especially for larger organizations. I will look into adding this feature sometime this week. Thanks again!

P5vc commented 3 years ago

Alright, manual class assignments have been added. As this is brand new (and required rewriting most of the script), I would greatly appreciate it if you could test it out and let me know if there are any bugs, issues, etc. that slipped through my testing. Thanks!

P.S. I'll be updating the documentation shortly (within an hour), explaining how to handle manual class assignments, in case you happen to see this message right away.

P5vc commented 3 years ago

Here's the documentation on adding manual class assignments:

https://github.com/P5vc/FetchApply#classes

Long story short, simply add an assignments file within classes that you wish to manually assign hosts to, and then list those hosts' hostnames one per line in the file.

Also, make sure to use the installation script to uninstall Fetch Apply, and then reinstall it on any system you test this on, as it will require a new configuration file and updated codebase.

emmetog commented 3 years ago

Looks great, will give it a spin! Thanks @P5vc!

P5vc commented 3 years ago

Looks great, will give it a spin! Thanks @P5vc!

No problem! Let me know how it goes!

Also, feel free to use the new class detection command (sudo fa list-classes-to-run), which will run just the detection phase, so you can verify exactly which classes it plans to run and make sure that it's correctly detecting any automatic and/or manual assignments.