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