-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_install_webserver.yaml
82 lines (69 loc) · 2.14 KB
/
11_install_webserver.yaml
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
---
# let's make a more real-life playbook
# This playbook will :
# - install apache and prerequisites
# - configure a new website root-folder
# - copy an index.html file, processed from a template
# - copy a config file, processed from a template
# - enable the the new website
# - disable the default apache website
# - make firewall whole of the web-port
# - apply a few handlers to restart/reload apache
- name: install a simple webserver on an ubuntu and copy 1 html file based on jinja j2 template
hosts: localhost
vars_files:
- vars/families.yaml
- vars/webserver.yaml
vars:
package_name: apache2
package_state: present
webserver_root: /var/www/html
webserver_index: index.html
webserver_template: index.html.j2
tasks:
- name: Install prerequisites
apt: name={{ item }} update_cache=yes state=latest force_apt_get=yes
loop: [ 'aptitude' ]
- name: Install Apache
apt: name=apache2 update_cache=yes state=latest
- name: Create document root
file:
path: "/var/www/{{ http_host }}"
state: directory
owner: "{{ app_user }}"
mode: '0755'
- name: Copy index test page
template:
src: "templates/index.html.j2"
dest: "/var/www/{{ http_host }}/index.html"
- name: Set up Apache virtuahHost
template:
src: "templates/apache.conf.j2"
dest: "/etc/apache2/sites-available/{{ http_conf }}"
- name: Enable new site
shell: /usr/sbin/a2ensite {{ http_conf }}
notify: Reload Apache
- name: Disable default Apache site
shell: /usr/sbin/a2dissite 000-default.conf
when: disable_default
notify: Reload Apache
- name: "UFW - Allow HTTP on port {{ http_port }}"
ufw:
rule: allow
port: "{{ http_port }}"
proto: tcp
handlers:
- name: Reload Apache
service:
name: apache2
state: reloaded
- name: Restart Apache
service:
name: apache2
state: restarted
# start and configure apache2
- name: start the apache2 service
service:
name: apache2
state: started
enabled: yes