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,
15 Optional[Array] $cron_pip = [],
17 $password_seed = lookup("base_installation::puppet_pass_seed")
18 include "base_installation"
20 include "profile::mail"
21 include "profile::tools"
22 include "profile::postgresql"
23 include "profile::apache"
24 include "profile::redis"
25 include "profile::monitoring"
27 ensure_packages(["python-pip", "python-virtualenv", "python-django"])
29 $caldance_app = "${home}/app"
30 $pg_password = generate_password(24, $password_seed, "postgres_caldance")
31 $secret_key = generate_password(24, $password_seed, "secret_key_caldance")
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,
41 "LOG_FILE" => "$home/caldev_django.log",
42 "MEDIA_ROOT" => "$home/media",
44 $shell_env = $environment.map |$key, $value| { "$key=$value" }
45 $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" }
50 file { "${home}/caldev_django.log":
57 ensure => "directory",
61 require => User["$user:"],
63 file { "${home}/media":
64 ensure => "directory",
70 exec { "initialize_venv":
72 require => User["$user:"],
73 command => "/usr/bin/virtualenv ${home}/virtualenv",
74 creates => "${home}/virtualenv",
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,
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]],
90 exec { "py-requirements":
93 environment => concat(["HOME=${home}"], $shell_env),
94 command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade",
95 require => User["$user:"],
101 environment => concat(["HOME=${home}"], $shell_env),
102 command => "$caldance_app/manage.py migrate",
103 require => [User["$user:"], File["$caldance_app/manage.py"]],
107 cwd => $caldance_app,
109 environment => concat(["HOME=${home}"], $shell_env),
110 command => "$caldance_app/manage.py collectstatic --no-input",
111 require => [User["$user:"], File["$caldance_app/manage.py"]],
114 exec { "reload httpd":
115 command => "/usr/bin/systemctl reload httpd",
116 require => [User["$user:"], File["$caldance_app/manage.py"]],
120 $python_path = "${home}/virtualenv/bin/python"
121 file { "$caldance_app/manage.py":
125 content => template("role/caldance/manage.py.erb"),
128 Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
132 profile::postgresql::master { "postgresql master for caldance":
133 letsencrypt_host => $web_host,
134 backup_hosts => ["backup-1"],
137 postgresql::server::db { $pg_db:
139 password => postgresql_password($pg_user, $pg_password),
142 # pour le script de génération de mdp
143 ensure_packages(["perl-digest-sha1"])
145 ensure_packages(["postgis", "python-gdal", "ripgrep"])
146 file { "/usr/local/bin/ldap_ssha":
150 source => "puppet:///modules/base_installation/scripts/ldap_ssha",
151 require => Package["perl-digest-sha1"],
154 sudo::conf { 'wheel_nopasswd':
156 content => "%wheel ALL=(ALL) NOPASSWD: ALL",
157 require => Package["sudo"],
160 ensure_packages(["mod_wsgi"])
161 class { 'apache::mod::wsgi':
162 wsgi_python_home => "${home}/virtualenv",
163 wsgi_python_path => $caldance_app,
164 require => Package["mod_wsgi"],
166 class { 'apache::mod::authn_file': }
167 class { 'apache::mod::authn_core': }
168 class { 'apache::mod::authz_user': }
169 class { 'apache::mod::auth_basic': }
171 apache::vhost { $web_host:
174 manage_docroot => false,
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],
180 additional_includes => "$home/caldance_env",
183 path => "$caldance_app/main_app",
184 require => "all granted",
187 path => "$caldance_app/www/static",
188 require => "all granted",
191 path => "$home/media",
192 require => "all granted",
193 options => ["-Indexes"],
197 provider => "location",
198 require => "valid-user",
199 auth_type => "Basic",
200 auth_name => "Authentification requise",
201 auth_user_file => "$home/htpasswd",
207 path => "$caldance_app/www/static/",
211 path => "$home/media/",
214 setenv => $apache_env,
215 wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" };
216 default: * => $::profile::apache::apache_vhost_default;
219 $mailtos = join($cron_pip, ",")
220 cron::job { "list_outdated_pip_packages":
223 environment => concat(["HOME=${home}","MAILTO=${mailtos}"], $shell_env),
224 command => "${home}/virtualenv/bin/pip list --outdated",
227 require => Exec["initialize_venv"],