jdauphant / ansible-role-nginx

Ansible role to install and manage nginx configuration
655 stars 302 forks source link

Can I configure role do not remove sites-enabled? #173

Closed zherdev-artem closed 7 years ago

zherdev-artem commented 7 years ago

Thank you for great role.

I learning ansible now, and I just want to have possibility add new nginx sites configs, with an option to delete other sites configs or not, how I can do it?

I'm trying this code example and now I'm always Disable unmanaged sites.

new_site.yml

---
- hosts: lemp
  sudo: yes

  vars_files:
    - vars_nginx.yaml

  roles:
    - role: jdauphant.nginx

vars_nginx.yaml


---
nginx_official_repo: True
keep_only_specified: True

vdomain: example.com

nginx_sites:
  "{{ vdomain }}":
    - listen *:80
    - server_name {{ vdomain }}
    - index index.html index.htm index.php
    - access_log /var/log/nginx/{{ vdomain }}.access.log combined
    - error_log /var/log/nginx/{{ vdomain }}.error.log
    - root /srv/www/{{ vdomain }}/
    - location /server-status {
            stub_status on;
            access_log false;
            allow 127.0.0.1;
            deny all; }
    - location /php-status {
            fastcgi_param SCRIPT_FILENAME /srv/www/{{ vdomain }}$fastcgi_script_name;
            fastcgi_pass php;
            include fastcgi_params;
            access_log false;
            allow 127.0.0.1;
            deny all; }
    - location / { try_files $uri $uri/ /index.php$is_args$args; }
    - location ~ .php$ { 
        try_files $uri /index.php =404;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_connect_timeout 60;
        fastcgi_ignore_client_abort off;
        fastcgi_index index.php;
        fastcgi_intercept_errors on;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param SCRIPT_FILENAME /srv/www/{{ vdomain }}$fastcgi_script_name;
        fastcgi_pass php;
        fastcgi_read_timeout 180;
        fastcgi_send_timeout 180;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_temp_file_write_size 256k;
        include fastcgi_params; }

nginx_configs:
  upstream:
    - upstream php { server unix:/var/run/php5-fpm.sock fail_timeout=10s; }`
jdauphant commented 7 years ago

The option "keep_only_specified: True" always disable other configuration.

To select manually what you want to remove, you can use these variables:

nginx_remove_sites: []
nginx_remove_configs: []
nginx_remove_snippets: []
philipwigg commented 7 years ago

Hi @mrZherart

Unfortunately it's not possible to user a variable for the site name. This bit won't work:-

nginx_sites:
  "{{ vdomain }}":

This has been discussed a couple of times and there's no solution we know about. See https://github.com/jdauphant/ansible-role-nginx/issues/127 and https://github.com/jdauphant/ansible-role-nginx/issues/88 for example.

zherdev-artem commented 7 years ago

@philipwigg For some reason, I have everything working:

nginx_sites:
  "{{ vdomain }}":

I'm using ansible-playbook new_site.yml -e "vdomain=my-super-example.com" and see the required config name in sites-available and sites-enabled

@jdauphant Thank you!