-
Notifications
You must be signed in to change notification settings - Fork 0
/
webservers.yml
79 lines (69 loc) · 1.95 KB
/
webservers.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
---
- name: Configure webserver with nginx
hosts: webservers
become: true
vars:
tls_dir: /etc/nginx/ssl/
key_file: nginx.key
cert_file: nginx.crt
conf_file: /etc/nginx/sites-available/default
server_name: localhost
handlers:
- name: Restart nginx
ansible.builtin.service:
name: nginx
state: restarted
tasks:
- name: Ensure nginx is installed
ansible.builtin.package:
name: nginx
update_cache: true
- name: Create directories for TLS certificates
ansible.builtin.file:
path: "{{ tls_dir }}"
state: directory
mode: "0750"
notify: Restart nginx
- name: Copy TLS files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ tls_dir }}"
mode: "0600"
loop:
- "{{ key_file }}"
- "{{ cert_file }}"
notify: Restart nginx
# - name: Copy nginx config file
# ansible.builtin.copy:
# src: nginx.conf
# dest: /etc/nginx/sites-available/default
# mode: preserve
- name: Manage nginx config template
ansible.builtin.template:
src: nginx.conf.j2
dest: "{{ conf_file }}"
mode: "0644"
notify: Restart nginx
- name: Enable configuration
ansible.builtin.file:
dest: /etc/nginx/sites-enabled/default
src: /etc/nginx/sites-available/default
state: link
- name: Install home page
ansible.builtin.template:
src: index.html.j2
dest: /usr/share/nginx/html/index.html
mode: "0644"
- name: Restart nginx
ansible.builtin.meta: flush_handlers
- name: "Test it! https://localhost:8443/index.html"
delegate_to: localhost
become: false
ansible.builtin.uri:
url: "https://localhost:8443/index.html"
validate_certs: false
return_content: true
register: this
failed_when: "'Running on ' not in this.content"
tags:
- test