summaryrefslogtreecommitdiff
path: root/roles/nginx/tasks/main.yml
blob: 57816ceaa2a0fb52b5ba0a0afcbc9b113c9ece7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
- name: install nginx
  apt:
    name: "{{ nginx_pkg_variant }}"
    state: present

- name: remove nginx default config
  file:
    name: /etc/nginx/sites-enabled/default
    state: absent
  notify: restart nginx

- name: install nginx config.d files
  loop: "{{ nginx_conf_d_files }}"
  copy:
    src: "conf.d/{{ item }}.conf"
    dest: /etc/nginx/conf.d/
  notify: restart nginx

- name: install nginx config snippets
  loop: "{{ nginx_snippets }}"
  copy:
    src: "snippets/{{ item }}.conf"
    dest: /etc/nginx/snippets/
  notify: restart nginx

- name: generate Diffie-Hellman parameters
  openssl_dhparam:
    path: /etc/ssl/dhparams.pem
    size: 2048
  notify: restart nginx

- name: install nginx configs from template
  loop: "{{ nginx_vhosts | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'template' in item.value"
  template:
    src: "{{ item.value.template }}.conf.j2"
    dest: "/etc/nginx/sites-available/{{ item.key }}"
  notify: restart nginx

- name: install nginx configs from config data
  loop: "{{ nginx_vhosts | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  when: "'content' in item.value"
  copy:
    content: "{{ item.value.content }}"
    dest: "/etc/nginx/sites-available/{{ item.key }}"
  notify: restart nginx

- name: enable vhost config
  loop: "{{ nginx_vhosts | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  file:
    src: "../sites-available/{{ item.key }}"
    dest: "/etc/nginx/sites-enabled/{{ item.key }}"
    state: link
  notify: restart nginx

- name: generate acme certificate
  loop: "{{ nginx_vhosts | dict2items }}"
  loop_control:
    label: "{{ item.key }} ({{ item.value.hostnames | default([]) | join(', ') }})"
  when: "'acme' in item.value  and  item.value.acme"
  include_tasks: acme.yml