jdauphant / ansible-role-nginx

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

Allow for no default config to be generated #234

Open BenBE opened 6 years ago

BenBE commented 6 years ago

The created (and activate) default site (cf. defaults/main.yml) causes interference with configurations where the default host should be configured using a template (either cause a warning about duplicate sites or need to unconfigure things coming from the defaults). Would be nice if there was a simple way to suppress creation of the default site in cases I really want just a bare nginx with only the settings visible in my playbook.

Sample:

    - role: service.nginx
      nginx_sites:
        foo:
          template: foo.conf.j2
          server_name: foo.example.org

Expected behaviour: Produces only one site (enabled) named foo.

Actual behaviour: Produces two sites (enabled) called default and foo.

Workaround:

    - role: service.nginx
      keep_only_specified: true
      nginx_remove_sites:
        - default
      nginx_disabled_sites:
        - default
      nginx_sites:
        foo:
          template: foo.conf.j2
          server_name: foo.example.org

NB: Only removing default, without disabling it causes a templating error.

Alternatively /causing a warning on execution) you could override default:

    - role: service.nginx
      nginx_sites:
        default:
          template: foo.conf.j2
          server_name: foo.example.org

Possible desired config:

    - role: service.nginx
      suppress_default_site: true
      nginx_sites:
        foo:
          template: foo.conf.j2
          server_name: foo.example.org
jdauphant commented 6 years ago

Thanks for the report.

It's an unexpected behavior. Normally, default should be removed and if you replace "nginx_sites", no new default should be added. https://github.com/jdauphant/ansible-role-nginx/blob/a6aa5ed94a05ba84ec48a1e20bf203eafcbffe5a/tasks/remove-defaults.yml Can you name what files are in your filesystem after the role launch, is it sites-enabled/default.conf or sites-enabled/default ?

BenBE commented 6 years ago

The file is sites-enabled/default.conf

Locally using commit 68633437e49f0e740f4dcae7754e025755ab89c2

Further note: Running FreeBSD on that host; using the role to configure inside a cbsd jail.

Running with ansible 2.5.1 on Ubuntu; in case this matters.

jdauphant commented 6 years ago

Ok the file should not exist if it's not defined by you. What's the content ? It's what specify here : https://github.com/jdauphant/ansible-role-nginx/blob/master/defaults/main.yml#L49 or another things ? Do you have "nginx_keep_only_specified" at False (default) or True ?