nginxinc / ansible-role-nginx-config

Ansible role for configuring NGINX
https://galaxy.ansible.com/nginxinc/nginx_config
Apache License 2.0
157 stars 73 forks source link

Need a way to install custom modules #13

Closed StudioMaX closed 4 years ago

StudioMaX commented 4 years ago

To install nginx I use my own RPM repository (for CentOS 7/8). This is necessary because standard repositories (CentOS and the official nginx RPM repository) lack many necessary modules, for example https://github.com/leev/ngx_http_geoip2_module, https://github.com/google/ngx_brotli and a few else. Therefore, instead of compiling the nginx right on the production server, I build it locally and distribute it through my RPM repository, which was installed via pre_tasks before executing this role.

Is your feature request related to a problem? Please describe. Now we can install only those modules for which separate tasks have been created: njs, perl, waf (Nginx Plus), geoip (RHEL < 8), image_filter, rtmp (Nginx Plus), xslt. But we are not able to install any other module, since there is no task to install the list of extra packages.

Describe the solution you'd like All tasks for all operating systems must be changes to install any extra package BEFORE starting/restarting/reloading nginx. This must be some sort of

- name: "(Install: Linux) Install additional Package"
  package:
    name: "{{ nginx_additional_packages }}"
    state: "{{ nginx_state }}"
  when: nginx_install_from == "os_repository" # ???
  notify: "(Handler: All OSs) Reload NGINX"

Additional context

There is a second problem here, since neither the CentOS repositories nor the official nginx repos contain any other modules. From the ansible side, this will look exactly the same as if you set nginx_install_from == "os_repository", which means "do not install official nginx repository, just install package nginx with the system package manager". There will be no problems here as long as there is package nginx in the system or my own repositories. But what if we distribute our package with a different name, for example nginx-custom, so that when updating the packages via yum update, we do not accidentally install package nginx from some other repositories, which may have a version higher than in my own repository. Therefore, we need some way to specify the name of the nginx package, and, accordingly, all the modules for it (like package nginx-custom and modules nginx-custom-module-geoip2).

alessfg commented 4 years ago

A few thoughts:

  1. Anything related to installing modules should probably live in https://github.com/nginxinc/ansible-role-nginx instead of here. That being said, adding a list variable to the template for load_modules would make sense within this role.
  2. The modules that are currently supported reflect the modules that are officially supported in some way or shape by NGINX (you can check them here https://docs.nginx.com/nginx/admin-guide/dynamic-modules/dynamic-modules/). There're no plans at the moment to support installing custom or third party modules. That being said, a few modules have been added since modules were last tweaked in this role (including an in house supported brotli module). I'll work on implementing them as soon as I can.
  3. Following from the previous point, there're also no plans at the moment to support installing custom NGINX packages. Allowing to install NGINX from each distros package repository was the one exception (and is not recommended under most circumstances).
alessfg commented 4 years ago

I'm marking this issue as wontfix since there's no plans in the near future to support custom modules, but I've created a new issue to track the implementation of pending official supported modules in the ansible-role-nginx repo https://github.com/nginxinc/ansible-role-nginx/issues/314