Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template inheritance #92

Merged
merged 3 commits into from Apr 23, 2017
Merged

Conversation

oxyc
Copy link
Contributor

@oxyc oxyc commented Mar 25, 2017

This is just a POC of allowing template files to be overridden. It's based on #91 so only the last commit actually belongs to this PR.

Should we also add basic out of the box support for SSL?

@oxyc
Copy link
Contributor Author

oxyc commented Mar 25, 2017

As an example Drupal VM could then extend with:

nginc_conf_template: "templates/nginx.conf.j2"
nginx_vhost_template: "templates/nginx-vhost.conf.j2"
{% extends 'roles/geerlingguy.nginx/templates/nginx.conf.j2' %}

{% block http_gzip %}
    gzip on;
    gzip_proxied any;
    gzip_static on;
    gzip_http_version 1.0;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;
    gzip_comp_level 6;
    gzip_types
        text/plain
        text/css
        text/xml
        text/javascript
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/xml+rss
        application/xhtml+xml
        application/x-font-ttf
        application/x-font-opentype
        image/svg+xml
        image/x-icon;
    gzip_buffers 16 8k;
    gzip_min_length 512;
{% endblock %}
{% extends 'roles/geerlingguy.nginx/templates/vhost.j2' %}

{#
  This is required for the current default `index` and `error_log` values.
  We could also a) split it into more blocks b) break drupal VM BC and
  require `item.index` and live with error.log only logging errors.
#}
{% block server_basic %}
    listen {{ item.listen | default("80") }};

    server_name {{ item.server_name }};
    error_log /var/log/nginx/error.log info;
    root {{ item.root }};
    index index.php index.html index.htm;
{% endblock %}

{% block server_end %}
{% if item.is_php is defined and item.is_php %}
    location / {
        # Don't touch PHP for static content.
        try_files $uri $uri/ /index.php?$query_string;
    }

    # Don't allow direct access to PHP files in the vendor directory.
    location ~ /vendor/.*\.php$ {
        deny all;
        return 404;
    }

{% if drupal_major_version == 8 %}
    # Redirect common PHP files to their new locations.
    location ~ ^((?!.*(?:core)).*)/(install.php|rebuild.php) {
         return 301 $scheme://$host$1/core/$2$is_args$args;
    }
{% endif %}

    # Use fastcgi for all php files.
    location ~ \.php$|^/update.php {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_intercept_errors on;
        fastcgi_read_timeout {{ php_max_execution_time }};
        include fastcgi_params;
        fastcgi_pass {{ php_fpm_listen }};
    }

    location @rewrite {
        rewrite ^ /index.php;
    }

    location ~ ^/sites/.*/files/styles/ {
        try_files $uri @rewrite;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ (^|/)\. {
        return 403;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
{% endif %}
{% endblock %}

@geerlingguy
Copy link
Owner

Can you rebase this one now? Thanks for the help with this! I'd rather not create the new major release for this role until this is finished (it will also give me more time to test pre-DrupalCon... don't want to break things too badly right as more people start downloading for sprints!).

@geerlingguy
Copy link
Owner

One last request—can you add a short section to the README file explaining the functionality and give one example for how a playbook can add to the template by extending the template or overriding a template?

Now that you put this bug in my ear, I'm starting to see a lot of other roles where this would be the best way to keep the main role nice and focused on the 80% case yet allow people to easily configure the thousands of other options they might need (GitLab, Apache, MySQL, Varnish, etc.).

@oxyc
Copy link
Contributor Author

oxyc commented Apr 22, 2017

Once you're okay with the docs, I can open up a similar PR for the varnish role. I think those would be the most useful templates to be able to override downstream in Drupal VM.

Edit: Actually just looking at the other configuration templates makes me overwhelmed over how to split them into blocks...

@oxyc oxyc changed the title [WIP] Template inheritance Template inheritance Apr 22, 2017
@geerlingguy geerlingguy merged commit 072001b into geerlingguy:master Apr 23, 2017
@geerlingguy
Copy link
Owner

Thanks! I think starting minimally in the other places makes sense; and it seems that fewer people have had to touch the Varnish templates anyways—it's MySQL (crazy complex), Apache, and Nginx that I seem to have the most complaints about.

h3po pushed a commit to h3po/ansible-role-nginx that referenced this pull request Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants