From 70529e223d1c349a541c3845c768e884dc9da2e3 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Thu, 22 Oct 2015 10:25:30 +0200 Subject: [PATCH] nginx_vhosts[x].name now accepts list or string --- README.md | 2 +- tasks/vhost.yml | 14 +++++++------- templates/etc/nginx/sites-available/_base.j2 | 2 +- tests/test.yml | 9 +++------ 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3073c80..17f6b30 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ You can see many examples in: [tests/test.yml](tests/test.yml). #### Common - - `name`: (M) List of domain used. The first occurence is the most important! + - `name`: (M) Domain or list of domain used. - `template`: (M) template used to create vhost - `enable`: (O) Enable the vhost (default is true) - `delete`: (O) Delete the vhost (default is false) diff --git a/tasks/vhost.yml b/tasks/vhost.yml index f0d68a7..70cf081 100644 --- a/tasks/vhost.yml +++ b/tasks/vhost.yml @@ -2,7 +2,7 @@ - name: FILE | Create root folders (foreach nginx_vhosts) file: > - path={{ nginx_root }}/{{ item.name[0] }}/public + path={{ nginx_root }}/{{ item.name if item.name is string else item.name[0] }}/public state=directory owner={{ item.owner | default('www-data') }} group={{ item.group | default('www-data') }} @@ -13,7 +13,7 @@ - name: TEMPLATE | Create vhosts template: > src=etc/nginx/sites-available/{{ item.template }}.j2 - dest=/etc/nginx/sites-available/{{ item.name[0] }} + dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} with_items: nginx_vhosts notify: reload nginx when: item.delete is not defined or not item.delete @@ -23,16 +23,16 @@ # with_fileglob: "web/*" - name: FILE | Delete vhosts - file: dest=/etc/nginx/sites-enabled/{{ item.name[0] }} state=absent - file: dest=/etc/nginx/sites-available/{{ item.name[0] }} state=absent + file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent + file: dest=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} state=absent with_items: nginx_vhosts notify: reload nginx when: item.delete is defined and item.delete - name: FILE | Enable vhosts file: > - src=/etc/nginx/sites-available/{{ item.name[0] }} - dest=/etc/nginx/sites-enabled/{{ item.name[0] }} + src=/etc/nginx/sites-available/{{ item.name if item.name is string else item.name[0] }} + dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=link with_items: nginx_vhosts notify: reload nginx @@ -42,7 +42,7 @@ (item.delete is not defined or not item.delete) - name: FILE | Disable vhosts - file: dest=/etc/nginx/sites-enabled/{{ item.name[0] }} state=absent + file: dest=/etc/nginx/sites-enabled/{{ item.name if item.name is string else item.name[0] }} state=absent with_items: nginx_vhosts notify: reload nginx when: item.enable is defined and not item.enable diff --git a/templates/etc/nginx/sites-available/_base.j2 b/templates/etc/nginx/sites-available/_base.j2 index 70aa52e..1c3cf87 100644 --- a/templates/etc/nginx/sites-available/_base.j2 +++ b/templates/etc/nginx/sites-available/_base.j2 @@ -12,7 +12,7 @@ server { {% for port in __listen %} listen {{ port }}; {% endfor %} - server_name {{ item.name | join(' ') }}; + server_name {% if item.name is string %}{{ item.name }}{% else %}{{ item.name | join(' ') }}{% endif %}; {% if item.root is defined %} root {{ item.root }}; {% else %} diff --git a/tests/test.yml b/tests/test.yml index d647b65..d84ad60 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -30,21 +30,18 @@ - 'return 403;' '/gunther': - 'return 404;' - - name: - - 'test-php.local' + - name: 'test-php.local' upstream_params: - 'fastcgi_param FOO bar;' redirect_from: - 'www.test-php.local' template: '_php' - - name: - - 'test-proxy.local' + - name: 'test-proxy.local' listen: - 8080 template: '_proxy' upstream_name: 'test' - - name: - - 'deleted.local' + - name: 'deleted.local' template: '_base' delete: true roles: