Allow combined vhosts file

pull/100/head
David Lundgren 7 years ago
parent 57889e8ad6
commit d82765b396
  1. 4
      defaults/main.yml
  2. 20
      tasks/vhosts-combined.yml
  3. 26
      tasks/vhosts-individual.yml
  4. 26
      tasks/vhosts.yml
  5. 33
      templates/vhosts.j2

@ -15,6 +15,10 @@ nginx_package_name: "nginx"
nginx_conf_template: "nginx.conf.j2"
nginx_vhost_template: "vhost.j2"
# Whether not to use a combined or individual vhost files (individual | combined)
nginx_vhost_style: "individual"
__nginx_vhosts_filename: "vhosts.conf"
nginx_worker_processes: "{{ ansible_processor_vcpus | default(ansible_processor_count) }}"
nginx_worker_connections: "1024"
nginx_multi_accept: "off"

@ -0,0 +1,20 @@
---
- name: Detect combined vhost filename
set_fact:
nginx_vhosts_filename: "{{ __nginx_vhosts_filename }}"
when: nginx_vhosts_filename is not defined
- name: Add managed vhost config file (if any vhosts are configured).
template:
src: vhosts.j2
dest: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
mode: 0644
when: nginx_vhosts|length > 0
notify: reload nginx
- name: Remove managed vhost config file (if no vhosts are configured).
file:
path: "{{ nginx_vhost_path }}/{{ nginx_vhosts_filename }}"
state: absent
when: nginx_vhosts|length == 0
notify: reload nginx

@ -0,0 +1,26 @@
---
- name: Add managed vhost config files.
template:
src: "{{ item.template|default(nginx_vhost_template) }}"
dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
force: yes
owner: root
group: root
mode: 0644
when: item.state|default('present') != 'absent'
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Remove managed vhost config files.
file:
path: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
state: absent
when: item.state|default('present') == 'absent'
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Remove legacy vhosts.conf file.
file:
path: "{{ nginx_vhost_path }}/vhosts.conf"
state: absent
notify: reload nginx

@ -12,28 +12,4 @@
state: directory
notify: reload nginx
- name: Add managed vhost config files.
template:
src: "{{ item.template|default(nginx_vhost_template) }}"
dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
force: yes
owner: root
group: root
mode: 0644
when: item.state|default('present') != 'absent'
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Remove managed vhost config files.
file:
path: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
state: absent
when: item.state|default('present') == 'absent'
with_items: "{{ nginx_vhosts }}"
notify: reload nginx
- name: Remove legacy vhosts.conf file.
file:
path: "{{ nginx_vhost_path }}/vhosts.conf"
state: absent
notify: reload nginx
- include: vhosts-{{ nginx_vhost_style }}.yml

@ -0,0 +1,33 @@
{% for vhost in nginx_vhosts %}
server {
listen {{ vhost.listen | default('80 default_server') }};
{% if vhost.server_name is defined %}
server_name {{ vhost.server_name }};
{% endif %}
{% if vhost.root is defined %}
root {{ vhost.root }};
{% endif %}
index {{ vhost.index | default('index.html index.htm') }};
{% if vhost.error_page is defined %}
error_page {{ vhost.error_page }};
{% endif %}
{% if vhost.access_log is defined %}
access_log {{ vhost.access_log }};
{% endif %}
{% if vhost.error_log is defined %}
error_log {{ vhost.error_log }} error;
{% endif %}
{% if vhost.return is defined %}
return {{ vhost.return }};
{% endif %}
{% if vhost.extra_parameters is defined %}
{{ vhost.extra_parameters|indent(4) }}
{% endif %}
}
{% endfor %}