-
Notifications
You must be signed in to change notification settings - Fork 704
/
main.yml
117 lines (107 loc) · 3.37 KB
/
main.yml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
- name: Fetch OS dependent variables
include_vars:
file: '{{ item }}'
name: 'os_vars'
with_first_found:
- files:
- '{{ ansible_facts.distribution }}_{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.distribution }}.yml'
- '{{ ansible_facts.os_family }}_{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.os_family }}.yml'
skip: true
tags: always
# we only override variables with our default, if they have not been specified already
# by default the lookup functions finds all varnames containing the string, therefore
# we add ^ and $ to denote start and end of string, so this returns only exact matches
- name: Set OS dependent variables, if not already defined by user # noqa var-naming
set_fact:
'{{ item.key }}': '{{ item.value }}'
when: "not lookup('varnames', '^' + item.key + '$')"
with_dict: '{{ os_vars }}'
tags: always
- name: Create additional configuration
template:
src: "hardening.conf.j2"
dest: "/etc/nginx/conf.d/90.hardening.conf"
mode: '0600'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change configuration in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*server_tokens'
line: " server_tokens {{ nginx_server_tokens }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change ssl_protocols in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*ssl_protocols'
line: " ssl_protocols {{ nginx_ssl_protocols }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change ssl_prefer_server_ciphers in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*ssl_prefer_server_ciphers'
line: " ssl_prefer_server_ciphers {{ nginx_ssl_prefer_server_ciphers }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change client_max_body_size in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*client_max_body_size'
line: " client_max_body_size {{ nginx_client_max_body_size }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change client_body_buffer_size in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*client_body_buffer_size'
line: " client_body_buffer_size {{ nginx_client_body_buffer_size }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Change keepalive_timeout in main nginx.conf
lineinfile:
dest: "/etc/nginx/nginx.conf"
regexp: '^\s*keepalive_timeout'
line: " keepalive_timeout {{ nginx_keepalive_timeout }};"
insertafter: "http {"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx
- name: Remove default.conf
file:
path: "{{ item }}"
state: absent
when: nginx_remove_default_site
notify: Restart nginx
loop:
- "/etc/nginx/conf.d/default.conf"
- "/etc/nginx/sites-enabled/default"
- name: Generate dh group
openssl_dhparam:
path: "/etc/nginx/dh{{ nginx_dh_size }}.pem"
size: "{{ nginx_dh_size }}"
mode: '0640'
owner: "root"
group: "root"
notify: Restart nginx