]>
Commit | Line | Data |
---|---|---|
851ca3c6 | 1 | class role::caldance ( |
a25b5f82 IB |
2 | String $user, |
3 | String $group, | |
4 | String $home, | |
5 | String $web_host, | |
6 | String $pg_user, | |
7 | String $pg_db, | |
8 | String $mail_from, | |
9 | String $smtp_host, | |
10 | String $smtp_port, | |
11 | Optional[String] $pg_hostname = "/run/postgresql", | |
12 | Optional[String] $pg_port = "5432", | |
13 | Optional[String] $caldance_version = undef, | |
14 | Optional[String] $caldance_sha256 = undef, | |
01d9e644 | 15 | Optional[Array] $cron_pip = [], |
851ca3c6 | 16 | ) { |
a25b5f82 | 17 | $password_seed = lookup("base_installation::puppet_pass_seed") |
851ca3c6 IB |
18 | include "base_installation" |
19 | ||
01d9e644 | 20 | include "profile::mail" |
851ca3c6 IB |
21 | include "profile::tools" |
22 | include "profile::postgresql" | |
23 | include "profile::apache" | |
24 | include "profile::redis" | |
d8f933bd | 25 | include "profile::monitoring" |
851ca3c6 IB |
26 | |
27 | ensure_packages(["python-pip", "python-virtualenv", "python-django"]) | |
b3ac23bb | 28 | |
a25b5f82 | 29 | $caldance_app = "${home}/app" |
d3948290 IB |
30 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") |
31 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") | |
32 | ||
33 | $environment = { | |
34 | "DB_NAME" => $pg_db, | |
35 | "DB_USER" => $pg_user, | |
36 | "DB_PASSWORD" => $pg_password, | |
37 | "DB_HOST" => $pg_hostname, | |
38 | "DB_PORT" => $pg_port, | |
39 | "SECRET_KEY" => $secret_key, | |
40 | "DEBUG" => "False", | |
41 | "LOG_FILE" => "$home/caldev_django.log", | |
3f485c9e | 42 | "MEDIA_ROOT" => "$home/media", |
d3948290 IB |
43 | "FROM_EMAIL" => $mail_from, |
44 | "EMAIL_HOST" => $smtp_host, | |
45 | "EMAIL_PORT" => $smtp_port, | |
46 | } | |
47 | $shell_env = $environment.map |$key, $value| { "$key=$value" } | |
48 | $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" } | |
49 | ||
50 | file { $home: | |
51 | mode => "0755", | |
52 | } | |
53 | file { "${home}/caldev_django.log": | |
54 | mode => "0664", | |
55 | owner => $user, | |
56 | group => "http", | |
d3948290 | 57 | } |
a25b5f82 IB |
58 | |
59 | file { $caldance_app: | |
60 | ensure => "directory", | |
61 | mode => "0755", | |
62 | owner => $user, | |
63 | group => $group, | |
64 | require => User["$user:"], | |
459e12d0 IB |
65 | } -> |
66 | file { "${home}/media": | |
67 | ensure => "directory", | |
68 | mode => "0755", | |
69 | owner => "http", | |
70 | group => "http", | |
a25b5f82 IB |
71 | } |
72 | ||
73 | exec { "initialize_venv": | |
74 | user => $user, | |
75 | require => User["$user:"], | |
76 | command => "/usr/bin/virtualenv ${home}/virtualenv", | |
77 | creates => "${home}/virtualenv", | |
78 | } | |
79 | -> | |
80 | archive { "${home}/caldance_${caldance_version}.tar.gz": | |
81 | path => "${home}/caldance_${caldance_version}.tar.gz", | |
82 | source => "https://release.immae.eu/caldance/caldance_${caldance_version}.tar.gz", | |
83 | checksum_type => "sha256", | |
84 | checksum => $caldance_sha256, | |
85 | cleanup => false, | |
86 | extract => true, | |
87 | user => $user, | |
88 | username => lookup("base_installation::ldap_cn"), | |
89 | password => generate_password(24, $password_seed, "ldap"), | |
90 | extract_path => $caldance_app, | |
91 | require => [User["$user:"], File[$caldance_app]], | |
92 | } ~> | |
93 | exec { "py-requirements": | |
94 | cwd => $caldance_app, | |
95 | user => $user, | |
d3948290 | 96 | environment => concat(["HOME=${home}"], $shell_env), |
f22a16c8 | 97 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", |
a25b5f82 IB |
98 | require => User["$user:"], |
99 | refreshonly => true, | |
100 | } ~> | |
101 | exec { "py-migrate": | |
102 | cwd => $caldance_app, | |
103 | user => $user, | |
d3948290 | 104 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 105 | command => "$caldance_app/manage.py migrate", |
d3948290 | 106 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
107 | refreshonly => true, |
108 | } ~> | |
109 | exec { "py-static": | |
110 | cwd => $caldance_app, | |
111 | user => $user, | |
d3948290 | 112 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 113 | command => "$caldance_app/manage.py collectstatic --no-input", |
d3948290 | 114 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
115 | refreshonly => true, |
116 | } ~> | |
117 | exec { "reload httpd": | |
118 | command => "/usr/bin/systemctl reload httpd", | |
d3948290 | 119 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
120 | refreshonly => true, |
121 | } | |
122 | ||
a25b5f82 IB |
123 | $python_path = "${home}/virtualenv/bin/python" |
124 | file { "$caldance_app/manage.py": | |
125 | owner => $user, | |
126 | group => $group, | |
127 | mode => "0755", | |
128 | content => template("role/caldance/manage.py.erb"), | |
129 | require => [ | |
130 | User["$user:"], | |
131 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | |
132 | ], | |
133 | } | |
134 | ||
135 | profile::postgresql::master { "postgresql master for caldance": | |
136 | letsencrypt_host => $web_host, | |
137 | backup_hosts => ["backup-1"], | |
138 | } | |
139 | ||
140 | postgresql::server::db { $pg_db: | |
141 | user => $pg_user, | |
142 | password => postgresql_password($pg_user, $pg_password), | |
143 | } | |
144 | ||
b3ac23bb IB |
145 | # pour le script de génération de mdp |
146 | ensure_packages(["perl-digest-sha1"]) | |
147 | ||
a25b5f82 | 148 | ensure_packages(["postgis", "python-gdal", "ripgrep"]) |
b3ac23bb IB |
149 | file { "/usr/local/bin/ldap_ssha": |
150 | owner => "root", | |
151 | group => "root", | |
152 | mode => "0755", | |
153 | source => "puppet:///modules/base_installation/scripts/ldap_ssha", | |
154 | require => Package["perl-digest-sha1"], | |
155 | } | |
a25b5f82 IB |
156 | |
157 | sudo::conf { 'wheel_nopasswd': | |
158 | priority => 99, | |
159 | content => "%wheel ALL=(ALL) NOPASSWD: ALL", | |
160 | require => Package["sudo"], | |
161 | } | |
162 | ||
163 | ensure_packages(["mod_wsgi"]) | |
164 | class { 'apache::mod::wsgi': | |
d3948290 IB |
165 | wsgi_python_home => "${home}/virtualenv", |
166 | wsgi_python_path => $caldance_app, | |
a25b5f82 IB |
167 | require => Package["mod_wsgi"], |
168 | } | |
169 | class { 'apache::mod::authn_file': } | |
170 | class { 'apache::mod::authn_core': } | |
171 | class { 'apache::mod::authz_user': } | |
172 | class { 'apache::mod::auth_basic': } | |
173 | ||
174 | apache::vhost { $web_host: | |
175 | port => '443', | |
176 | docroot => false, | |
177 | manage_docroot => false, | |
178 | ssl => true, | |
179 | ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem", | |
180 | ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem", | |
181 | ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem", | |
182 | require => Letsencrypt::Certonly[$web_host], | |
183 | directories => [ | |
184 | { | |
d3948290 | 185 | path => "$caldance_app/main_app", |
a25b5f82 IB |
186 | require => "all granted", |
187 | }, | |
188 | { | |
d3948290 | 189 | path => "$caldance_app/www/static", |
a25b5f82 IB |
190 | require => "all granted", |
191 | }, | |
83341b3c IB |
192 | { |
193 | path => "$home/media", | |
194 | require => "all granted", | |
195 | options => ["-Indexes"], | |
196 | }, | |
a25b5f82 IB |
197 | { |
198 | path => "/", | |
199 | provider => "location", | |
200 | require => "valid-user", | |
201 | auth_type => "Basic", | |
202 | auth_name => "Authentification requise", | |
b1072a47 | 203 | auth_user_file => "$home/htpasswd", |
a25b5f82 IB |
204 | }, |
205 | ], | |
206 | aliases => [ | |
207 | { | |
208 | alias => "/static/", | |
d3948290 | 209 | path => "$caldance_app/www/static/", |
a25b5f82 | 210 | }, |
83341b3c IB |
211 | { |
212 | alias => "/media/", | |
213 | path => "$home/media/", | |
214 | }, | |
a25b5f82 | 215 | ], |
d3948290 IB |
216 | setenv => $apache_env, |
217 | wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" }; | |
a25b5f82 IB |
218 | default: * => $::profile::apache::apache_vhost_default; |
219 | } | |
01d9e644 IB |
220 | |
221 | $mailtos = join($cron_pip, ",") | |
222 | cron::job { "list_outdated_pip_packages": | |
223 | ensure => present, | |
224 | user => $user, | |
225 | environment => concat(["HOME=${home}","MAILTO=${mailtos}"], $shell_env), | |
226 | command => "${home}/virtualenv/bin/pip list --outdated", | |
227 | minute => "15", | |
228 | hour => "0", | |
229 | require => Exec["initialize_venv"], | |
230 | } | |
851ca3c6 | 231 | } |