forked from koddr/useful-playbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_brotli-playbook.yml
100 lines (85 loc) · 2.9 KB
/
install_brotli-playbook.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
# Ansible playbook for install Brotli module to exists Nginx on your server.
# For more information, please visit https://github.com/truewebartisans/useful-playbooks
# Author: Vic Shóstak <truewebartisans@gmail.com> & True web artisans (https://1wa.co)
# License: MIT
---
- hosts: "{{ host|default('localhost') }}"
become: true
tasks:
- name: Gather the apt package facts
package_facts:
manager: auto
- name: Get Nginx version and set variable
set_fact:
nginx_version: "{{ ansible_facts.packages['nginx'][0].version | regex_search('^[0-9.]*') }}"
- name: Install needed packages
apt:
pkg: "{{ item }}"
state: latest
with_items:
- git
- gcc
- cmake
- libpcre3
- libpcre3-dev
- zlib1g
- zlib1g-dev
- openssl
- libssl-dev
- name: Download and unarchive Nginx source code of version {{ nginx_version }}
unarchive:
src: https://nginx.org/download/nginx-{{ nginx_version }}.tar.gz
dest: ~/
remote_src: yes
- name: Git clone Brotli module (google/ngx_brotli)
git:
repo: https://github.com/google/ngx_brotli.git
dest: ~/ngx_brotli
- name: Configure Brotli module
command:
chdir: ~/nginx-{{ nginx_version }}
cmd: ./configure --with-compat --add-dynamic-module=../ngx_brotli
- name: Make Brotli module (Dynamically loaded)
make:
chdir: ~/nginx-{{ nginx_version }}
target: modules
- name: Copy compiled Brotli module to /usr/share/nginx/modules
copy:
remote_src: yes
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0644
with_items:
- { src: "~/nginx-{{ nginx_version }}/objs/ngx_http_brotli_filter_module.so", dest: "/usr/share/nginx/modules" }
- { src: "~/nginx-{{ nginx_version }}/objs/ngx_http_brotli_static_module.so", dest: "/usr/share/nginx/modules" }
- name: Add Brotli module to the start of Nginx config
lineinfile:
path: /etc/nginx/nginx.conf
insertbefore: BOF
line: "{{ item.line }}"
with_items:
- { line: 'load_module "modules/ngx_http_brotli_filter_module.so";' }
- { line: 'load_module "modules/ngx_http_brotli_static_module.so";' }
- name: Copy Brotli config
copy:
src: ./configs/brotli.conf
dest: /etc/nginx/conf.d/brotli.conf
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: 0644
notify:
- reload_nginx
- name: Delete unnecessary directories
file:
state: absent
path: "{{ item.path }}"
with_items:
- { path: "~/ngx_brotli" }
- { path: "~/nginx-{{ nginx_version }}" }
handlers:
- name: reload_nginx
service:
name: nginx
state: reloaded