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,
16 $password_seed = lookup("base_installation::puppet_pass_seed")
17 include "base_installation"
19 include "profile::tools"
20 include "profile::postgresql"
21 include "profile::apache"
22 include "profile::redis"
23 include "profile::monitoring"
25 ensure_packages(["python-pip", "python-virtualenv", "python-django"])
27 $caldance_app = "${home}/app"
28 $pg_password = generate_password(24, $password_seed, "postgres_caldance")
29 $secret_key = generate_password(24, $password_seed, "secret_key_caldance")
33 "DB_USER" => $pg_user,
34 "DB_PASSWORD" => $pg_password,
35 "DB_HOST" => $pg_hostname,
36 "DB_PORT" => $pg_port,
37 "SECRET_KEY" => $secret_key,
39 "LOG_FILE" => "$home/caldev_django.log",
40 "FROM_EMAIL" => $mail_from,
41 "EMAIL_HOST" => $smtp_host,
42 "EMAIL_PORT" => $smtp_port,
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:"],
64 exec { "initialize_venv":
66 require => User["$user:"],
67 command => "/usr/bin/virtualenv ${home}/virtualenv",
68 creates => "${home}/virtualenv",
71 archive { "${home}/caldance_${caldance_version}.tar.gz":
72 path => "${home}/caldance_${caldance_version}.tar.gz",
73 source => "https://release.immae.eu/caldance/caldance_${caldance_version}.tar.gz",
74 checksum_type => "sha256",
75 checksum => $caldance_sha256,
79 username => lookup("base_installation::ldap_cn"),
80 password => generate_password(24, $password_seed, "ldap"),
81 extract_path => $caldance_app,
82 require => [User["$user:"], File[$caldance_app]],
84 exec { "py-requirements":
87 environment => concat(["HOME=${home}"], $shell_env),
88 command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade",
89 require => User["$user:"],
95 environment => concat(["HOME=${home}"], $shell_env),
96 command => "$caldance_app/manage.py migrate",
97 require => [User["$user:"], File["$caldance_app/manage.py"]],
101 cwd => $caldance_app,
103 environment => concat(["HOME=${home}"], $shell_env),
104 command => "$caldance_app/manage.py collectstatic --no-input",
105 require => [User["$user:"], File["$caldance_app/manage.py"]],
108 exec { "reload httpd":
109 command => "/usr/bin/systemctl reload httpd",
110 require => [User["$user:"], File["$caldance_app/manage.py"]],
114 $python_path = "${home}/virtualenv/bin/python"
115 file { "$caldance_app/manage.py":
119 content => template("role/caldance/manage.py.erb"),
122 Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
126 profile::postgresql::master { "postgresql master for caldance":
127 letsencrypt_host => $web_host,
128 backup_hosts => ["backup-1"],
131 postgresql::server::db { $pg_db:
133 password => postgresql_password($pg_user, $pg_password),
136 # pour le script de génération de mdp
137 ensure_packages(["perl-digest-sha1"])
139 ensure_packages(["postgis", "python-gdal", "ripgrep"])
140 file { "/usr/local/bin/ldap_ssha":
144 source => "puppet:///modules/base_installation/scripts/ldap_ssha",
145 require => Package["perl-digest-sha1"],
148 sudo::conf { 'wheel_nopasswd':
150 content => "%wheel ALL=(ALL) NOPASSWD: ALL",
151 require => Package["sudo"],
154 ensure_packages(["mod_wsgi"])
155 class { 'apache::mod::wsgi':
156 wsgi_python_home => "${home}/virtualenv",
157 wsgi_python_path => $caldance_app,
158 require => Package["mod_wsgi"],
160 class { 'apache::mod::authn_file': }
161 class { 'apache::mod::authn_core': }
162 class { 'apache::mod::authz_user': }
163 class { 'apache::mod::auth_basic': }
165 apache::vhost { $web_host:
168 manage_docroot => false,
170 ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem",
171 ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem",
172 ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem",
173 require => Letsencrypt::Certonly[$web_host],
176 path => "$caldance_app/main_app",
177 require => "all granted",
180 path => "$caldance_app/www/static",
181 require => "all granted",
185 provider => "location",
186 require => "valid-user",
187 auth_type => "Basic",
188 auth_name => "Authentification requise",
189 auth_user_file => "$home/htpasswd",
195 path => "$caldance_app/www/static/",
198 setenv => $apache_env,
199 wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" };
200 default: * => $::profile::apache::apache_vhost_default;