Ansible-role-nginx-config: Ability to upload snippets

Created on 30 Jul 2020  ·  5Comments  ·  Source: nginxinc/ansible-role-nginx-config

Is your feature request related to a problem? Please describe.
It would be really handy to be able to upload a snippets directory containing configuration files, so that one can reuse common configuration in other nginx http conf files. If I'm not mistaken, I don't believe that this is currently (explicitly) possible in this plugin.

Describe alternatives you've considered
Tried using nginx_main_upload_src and nginx_http_upload_src, but neither work in this case. nginx_main_upload_src expects a file, and nginx_http_upload_src uses fileglob, which does not allow for recursive copies.

I could obviously do this in a separate role, but it would be nice to have all the nginx configuration done in the same role.

Describe the solution you'd like
One solution would be to emulate existing upload variable options, such as nginx_http_upload_enable. For example, introducing the vars: nginx_snippets_upload_enable, as well as src and dest counterparts would be nice.

If you feel that this solution is too specific to snippets, perhaps there is a more general way to copy local files to the root of the remote nginx directory. This is sort of how it's done in this Ansible nginx plugin: https://github.com/tschifftner/ansible-role-nginx#use-additional-nginx-templates

Alternatively making it possible to recursively possible to upload directories to the http config directory would be another way to go, though I'm not a fan of this as it doesn't match the defacto nginx directory structure, where snippets is on the root.

Thanks!

feature

Most helpful comment

@asabhaney I finally got around implementing snippets support in #59.

FWIW, I might revisit how uploading configuration files works for the other nginx_config_*_upload_* variables at some stage (might even remove some of them) since I am not entirely happy with the assumptions/little configurability made behind the scenes by the respective tasks (and I think the snippets option can be used just as well for the main/http/stream configuration upload tasks).

All 5 comments

Interesting suggestion @asabhaney! I can't promise when/if this will get worked on (there's a few other tasks on the backlog with a higher priority at the moment), but feel free to submit a PR if you want 😄

Hey again!

I'm looking at the suggested plugin you shared and I have a couple thoughts about it.

  1. The example in that plugin could be replicated using nginx_http_upload_*, although I do get that if you want to upload both config and snippets files to different destination folders, nginx_http_upload_* will only let you choose one source and destination at a time.
  2. There is no snippets concept within NGINX's defacto directory structure. That's a concept introduced in the plugin you linked. Not that there's anything wrong with it, but it's not necessarily a recommended folder structure.

Duplicating nginx_http_upload_* to create a nginx_snippets_upload_* variable should be easy enough. A better question would be whether it'd make more sense to let users use a list when using nginx_*_upload_* and in doing so simplify the whole series of upload related variables.

Hey @alessfg, thanks for taking the time to look into this! I agree that there's no defacto directory structure references to snippets (though I have seen it scattered throughout Nginx's documentation). I also agree that it's too specific and bloating to add a set of vars (nginx_snippets_upload_*) for it.

I think that being able to upload any additional folders/files to the root nginx directory is a better general solution. Not sure whether that should include replacing vars such as nginx_http_upload_* (not to mention backward breaking), or it should be in the form of something like nginx_other_upload_*, which could take in a list.

@asabhaney I finally got around implementing snippets support in #59.

FWIW, I might revisit how uploading configuration files works for the other nginx_config_*_upload_* variables at some stage (might even remove some of them) since I am not entirely happy with the assumptions/little configurability made behind the scenes by the respective tasks (and I think the snippets option can be used just as well for the main/http/stream configuration upload tasks).

Great thanks, can't wait to use it!

Was this page helpful?
0 / 5 - 0 ratings