Giter Club home page Giter Club logo

Comments (12)

AlekseiSidorenko avatar AlekseiSidorenko commented on August 18, 2024 13

Hi there!
Guys, could you please provide any updates regarding the variables using in nginx.conf and templates of http blocks? Will it be possible to use j2 templates for generating virtual hosts in the next releases?

Thanks in advance!

from ansible-role-nginx.

alessfg avatar alessfg commented on August 18, 2024 2

Quick update - more advanced main/http templating options are almost done and ready to be released. The way templates work has been slightly reworked and should hopefully provide further flexibility on how to approach templating.

from ansible-role-nginx.

alessfg avatar alessfg commented on August 18, 2024 1

@Uhanga88 support for virtual hosts is still on the roadmap but I cannot provide an ETA. Re nginx.conf templating are there any extra specific variables that you'd like to see included in the nginx.conf.j2 template?

from ansible-role-nginx.

sseide avatar sseide commented on August 18, 2024 1

For the time until all this variables are implemented it would be really helpful to have role variables specifying my own template to use instead of the one provided by the role iteself. Currently (as far as i understand) it is only possible to push my own configuration files via copy - there are no modifications possible anymore at this point and i have to somehow create them locally as needed as the copy operation in use does not allow setting remote source (an file i templated before) as copy source.

Or do i miss something?

Thanks in advance

from ansible-role-nginx.

alessfg avatar alessfg commented on August 18, 2024 1

There are some tentative plans to refactor this role into smaller roles with more concise functionalities. One of the smaller roles would be dedicated to templating vs installing NGINX, and should make both roles run faster if you only need the functionality of one of them.

from ansible-role-nginx.

alessfg avatar alessfg commented on August 18, 2024

Hi @robgarner!

The variables are already implemented (although admittedly the implementation is very basic at this stage). The idea is to use main_template_* to manage the nginx.conf file, http_template_* to manage http blocks, and stream_template_* to manage stream blocks.

For example, you can use main_template_enable by setting its value to true. You can then set other values such as main_template_user or main_template_error_level to tweak nginx.conf values (you can find these values and their defaults at defaults/main.yml).

As far as further development of NGINX templating goes - the plan is to gradually add support for all the major NGINX directives - starting with the main nginx.conf templating, then moving to http blocks, and finally moving to stream blocks.

from ansible-role-nginx.

akx avatar akx commented on August 18, 2024

I agree with @sseide – being able to set a custom template filename would be really useful to be able to just have a

  - role: nginx
    tags: nginx
    vars:
      nginx_main_template_file: "templates/my.custom.nginx.conf.j2"

dependency stanza and have everything approximately work :)

from ansible-role-nginx.

shamsalmon avatar shamsalmon commented on August 18, 2024

@alessfg geerlingguy has some pretty great templating in his role. Since ansible 2.6 you can actually separate out your defaults/ vars files if you want to look into that.

from ansible-role-nginx.

carlba avatar carlba commented on August 18, 2024

I have implemented faux vhost support by doing this

- name: install and configure the reverse proxied HTTPS servers
  include_role:
    name: nginxinc.nginx
  vars:
    nginx_http_template_enable: true
    nginx_http_template:
      '{{ vhost.name }}':
        port: 443
        server_name: "{{ vhost.fqdn }}"
        autoindex: false
        template_file: http/default.conf.j2
        conf_file_name: '{{ vhost.name }}.conf'
        conf_file_location: /etc/nginx/conf.d/
        ssl:
          cert: "/etc/letsencrypt/live/{{ vhost.fqdn }}/fullchain.pem"
          key: "/etc/letsencrypt/live/{{ vhost.fqdn }}/privkey.pem"
        web_server:
          locations: []
          http_demo_conf: false
        reverse_proxy:
          locations:
            backend:
              location: /
              proxy_pass: 'http://{{ vhost.name }}'
              websocket: true
          health_check_plus: false
        upstreams:
          '{{ vhost.name }}':
            name: '{{ vhost.name }}'
            lb_method: least_conn
            zone_name: '{{ vhost.name }}'
            zone_size: 64k
            sticky_cookie: false
            servers:
              '{{ vhost.name }}':
                address: '{{ vhost.local_ip }}'
                port: '{{ vhost.local_port }}'
                weight: 1
                health_check: max_fails=1 fail_timeout=10s
    nginx_html_demo_template_enable: false
  loop: '{{ proxied_vhosts }}'
  loop_control:
    loop_var: 'vhost'

from ansible-role-nginx.

carlba avatar carlba commented on August 18, 2024

The bad thing with this solution is that the installation phase of the role must be run for every vhost. Would it be possible to provide an option to not do the installation part of the role until the vhost support is implemented that would save me a lot of time :)

Just realised this is already possible by

nginx_enable: false

from ansible-role-nginx.

carlba avatar carlba commented on August 18, 2024

it's still takes quite a long time to just skip all the steps though.

from ansible-role-nginx.

alessfg avatar alessfg commented on August 18, 2024

There's now way better templating support, including variables to add any number of additional custom options and include other configuration files in your system to your NGINX configuration. Doing some prep work before the next release, at which point all these new templating options should also be available on Ansible Galaxy.

from ansible-role-nginx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.