aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/nginx/tasks/main.yml
blob: e6060f190486696b93e4cdcde47c093c2d5cdb5e (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
69
70
71
72
73
74
---
- name: Install NGINX & modules
  package:
    name:
      - nginx
      - libnginx-mod-http-lua
      - libnginx-mod-http-geoip
    state: present
  tags:
    - role::nginx

- name: Copy NGINX default config
  template:
    src: default_server.conf
    dest: /etc/nginx/conf.d/default_server.conf
    group: root
    owner: root
    mode: "0644"
  tags:
    - role::nginx
  notify:
    - Reload the nginx service

- name: Remove default nginx site
  file:
    path: /etc/nginx/sites-enabled/default
    state: absent
  tags:
    - role::nginx

- name: Copy conf.d entries
  template:
    src: "{{ item }}"
    dest: "/etc/nginx/conf.d/{{ item | basename | splitext | first }}"
    mode: "0444"
    owner: root
    group: root
  with_fileglob: "../templates/nginx-conf.d/*"
  loop_control:
    label: "{{ item | basename | splitext | first }}"
  tags:
    - role::nginx
  notify:
    - Reload the nginx service

- name: Copy host-specific configs
  copy:
    content: |
      # Ansible managed
      {{ item.value }}
    dest: "/etc/nginx/sites-available/{{ item.key }}"
    mode: "0644"
    group: root
    owner: root
  with_items:
    - "{{ nginx_configs | dict2items }}"
  tags:
    - role::nginx
  when: nginx_configs is defined
  notify:
    - Reload the nginx service

- name: Enable host-specific sites
  file:
    src: "/etc/nginx/sites-available/{{ item }}"
    dest: "/etc/nginx/sites-enabled/{{ item }}"
    state: link
  with_items:
    - "{{ nginx_configs.keys() }}"
  tags:
    - role::nginx
  when: nginx_configs is defined
  notify:
    - Reload the nginx service