-
Notifications
You must be signed in to change notification settings - Fork 0
/
101-setup_web_static.pp
69 lines (59 loc) · 1.84 KB
/
101-setup_web_static.pp
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
include stdlib
# Update package lists
exec { 'Update lists':
command => '/usr/bin/apt update'
}
# Install Nginx
package { 'nginx':
ensure => 'present',
require => Exec['Update lists']
}
# Create the directory tree
exec { 'Create Directory Tree':
command => '/bin/mkdir -p /data/web_static/releases/test /data/web_static/shared',
require => Package['nginx']
}
$head = " <head>\n </head>"
$body = " <body>\n Holberton School\n </body>"
$index = "<html>\n${head}\n${body}\n</html>\n"
# Create a fake HTML file with simple content,
# to test Nginx configuration
file { 'Create Fake HTML':
ensure => 'present',
path => '/data/web_static/releases/test/index.html',
content => $index,
require => Exec['Create Directory Tree']
}
# Create a symbolic link '/data/web_static/current' linked to the
# '/data/web_static/releases/test/' folder.
file { 'Create Symbolic Link':
ensure => 'link',
path => '/data/web_static/current',
force => true,
target => '/data/web_static/releases/test',
require => File['Create Fake HTML']
}
# Ensures that Nginx is running
service { 'nginx':
ensure => 'running',
enable => true,
require => Package['nginx']
}
# Set permissions for 'ubuntu' user
exec { 'Set permissions':
command => '/bin/chown -R ubuntu:ubuntu /data',
require => File['Create Symbolic Link']
}
# Set a new location for a Nginx VHost
$loc_header='location /hbnb_static/ {'
$loc_content='alias /data/web_static/current/;'
$new_location="\n\t${loc_header}\n\t\t${loc_content}\n\t}\n"
# Write the new location to the default Nginx VHost
file_line { 'Set Nginx Location':
ensure => 'present',
path => '/etc/nginx/sites-available/default',
after => 'server_name \_;',
line => $new_location,
notify => Service['nginx'],
require => Exec['Set permissions']
}