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