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",
43 "FROM_EMAIL" => $mail_from,
44 "EMAIL_HOST" => $smtp_host,
45 "EMAIL_PORT" => $smtp_port,
47 $shell_env = $environment.map |$key, $value| { "$key=$value" }
48 $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" }
53 file { "${home}/caldev_django.log":
60 ensure => "directory",
64 require => User["$user:"],
66 file { "${home}/media":
67 ensure => "directory",
73 exec { "initialize_venv":
75 require => User["$user:"],
76 command => "/usr/bin/virtualenv ${home}/virtualenv",
77 creates => "${home}/virtualenv",
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,
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]],
93 exec { "py-requirements":
96 environment => concat(["HOME=${home}"], $shell_env),
97 command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade",
98 require => User["$user:"],
102 cwd => $caldance_app,
104 environment => concat(["HOME=${home}"], $shell_env),
105 command => "$caldance_app/manage.py migrate",
106 require => [User["$user:"], File["$caldance_app/manage.py"]],
110 cwd => $caldance_app,
112 environment => concat(["HOME=${home}"], $shell_env),
113 command => "$caldance_app/manage.py collectstatic --no-input",
114 require => [User["$user:"], File["$caldance_app/manage.py"]],
117 exec { "py-symlink-file":
118 cwd => $caldance_app,
120 environment => concat(["HOME=${home}"], $shell_env),
121 command => "/usr/bin/ln -sf ${home}/media www/media",
122 require => [User["$user:"], File["$caldance_app/manage.py"]],
125 exec { "reload httpd":
126 command => "/usr/bin/systemctl reload httpd",
127 require => [User["$user:"], File["$caldance_app/manage.py"]],
131 $python_path = "${home}/virtualenv/bin/python"
132 file { "$caldance_app/manage.py":
136 content => template("role/caldance/manage.py.erb"),
139 Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
143 profile::postgresql::master { "postgresql master for caldance":
144 letsencrypt_host => $web_host,
145 backup_hosts => ["backup-1"],
148 postgresql::server::db { $pg_db:
150 password => postgresql_password($pg_user, $pg_password),
153 # pour le script de génération de mdp
154 ensure_packages(["perl-digest-sha1"])
156 ensure_packages(["postgis", "python-gdal", "ripgrep"])
157 file { "/usr/local/bin/ldap_ssha":
161 source => "puppet:///modules/base_installation/scripts/ldap_ssha",
162 require => Package["perl-digest-sha1"],
165 sudo::conf { 'wheel_nopasswd':
167 content => "%wheel ALL=(ALL) NOPASSWD: ALL",
168 require => Package["sudo"],
171 ensure_packages(["mod_wsgi"])
172 class { 'apache::mod::wsgi':
173 wsgi_python_home => "${home}/virtualenv",
174 wsgi_python_path => $caldance_app,
175 require => Package["mod_wsgi"],
177 class { 'apache::mod::authn_file': }
178 class { 'apache::mod::authn_core': }
179 class { 'apache::mod::authz_user': }
180 class { 'apache::mod::auth_basic': }
182 apache::vhost { $web_host:
185 manage_docroot => false,
187 ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem",
188 ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem",
189 ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem",
190 require => Letsencrypt::Certonly[$web_host],
193 path => "$caldance_app/main_app",
194 require => "all granted",
197 path => "$caldance_app/www/static",
198 require => "all granted",
202 provider => "location",
203 require => "valid-user",
204 auth_type => "Basic",
205 auth_name => "Authentification requise",
206 auth_user_file => "$home/htpasswd",
212 path => "$caldance_app/www/static/",
215 setenv => $apache_env,
216 wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" };
217 default: * => $::profile::apache::apache_vhost_default;
220 $mailtos = join($cron_pip, ",")
221 cron::job { "list_outdated_pip_packages":
224 environment => concat(["HOME=${home}","MAILTO=${mailtos}"], $shell_env),
225 command => "${home}/virtualenv/bin/pip list --outdated",
228 require => Exec["initialize_venv"],