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 "FROM_EMAIL" => $mail_from,
43 "EMAIL_HOST" => $smtp_host,
44 "EMAIL_PORT" => $smtp_port,
46 $shell_env = $environment.map |$key, $value| { "$key=$value" }
47 $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" }
52 file { "${home}/caldev_django.log":
59 ensure => "directory",
63 require => User["$user:"],
65 file { "${home}/media":
66 ensure => "directory",
72 exec { "initialize_venv":
74 require => User["$user:"],
75 command => "/usr/bin/virtualenv ${home}/virtualenv",
76 creates => "${home}/virtualenv",
79 archive { "${home}/caldance_${caldance_version}.tar.gz":
80 path => "${home}/caldance_${caldance_version}.tar.gz",
81 source => "https://release.immae.eu/caldance/caldance_${caldance_version}.tar.gz",
82 checksum_type => "sha256",
83 checksum => $caldance_sha256,
87 username => lookup("base_installation::ldap_cn"),
88 password => generate_password(24, $password_seed, "ldap"),
89 extract_path => $caldance_app,
90 require => [User["$user:"], File[$caldance_app]],
92 exec { "py-requirements":
95 environment => concat(["HOME=${home}"], $shell_env),
96 command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade",
97 require => User["$user:"],
101 cwd => $caldance_app,
103 environment => concat(["HOME=${home}"], $shell_env),
104 command => "$caldance_app/manage.py migrate",
105 require => [User["$user:"], File["$caldance_app/manage.py"]],
109 cwd => $caldance_app,
111 environment => concat(["HOME=${home}"], $shell_env),
112 command => "$caldance_app/manage.py collectstatic --no-input",
113 require => [User["$user:"], File["$caldance_app/manage.py"]],
116 exec { "py-symlink-file":
117 cwd => $caldance_app,
119 environment => concat(["HOME=${home}"], $shell_env),
120 command => "/usr/bin/ln -sf ${home}/media www/media",
121 require => [User["$user:"], File["$caldance_app/manage.py"]],
124 exec { "reload httpd":
125 command => "/usr/bin/systemctl reload httpd",
126 require => [User["$user:"], File["$caldance_app/manage.py"]],
130 $python_path = "${home}/virtualenv/bin/python"
131 file { "$caldance_app/manage.py":
135 content => template("role/caldance/manage.py.erb"),
138 Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
142 profile::postgresql::master { "postgresql master for caldance":
143 letsencrypt_host => $web_host,
144 backup_hosts => ["backup-1"],
147 postgresql::server::db { $pg_db:
149 password => postgresql_password($pg_user, $pg_password),
152 # pour le script de génération de mdp
153 ensure_packages(["perl-digest-sha1"])
155 ensure_packages(["postgis", "python-gdal", "ripgrep"])
156 file { "/usr/local/bin/ldap_ssha":
160 source => "puppet:///modules/base_installation/scripts/ldap_ssha",
161 require => Package["perl-digest-sha1"],
164 sudo::conf { 'wheel_nopasswd':
166 content => "%wheel ALL=(ALL) NOPASSWD: ALL",
167 require => Package["sudo"],
170 ensure_packages(["mod_wsgi"])
171 class { 'apache::mod::wsgi':
172 wsgi_python_home => "${home}/virtualenv",
173 wsgi_python_path => $caldance_app,
174 require => Package["mod_wsgi"],
176 class { 'apache::mod::authn_file': }
177 class { 'apache::mod::authn_core': }
178 class { 'apache::mod::authz_user': }
179 class { 'apache::mod::auth_basic': }
181 apache::vhost { $web_host:
184 manage_docroot => false,
186 ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem",
187 ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem",
188 ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem",
189 require => Letsencrypt::Certonly[$web_host],
192 path => "$caldance_app/main_app",
193 require => "all granted",
196 path => "$caldance_app/www/static",
197 require => "all granted",
201 provider => "location",
202 require => "valid-user",
203 auth_type => "Basic",
204 auth_name => "Authentification requise",
205 auth_user_file => "$home/htpasswd",
211 path => "$caldance_app/www/static/",
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"],