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 $web_home = "/home/simon_descarpentries"
18 include "base_installation"
20 include "profile::tools"
21 include "profile::postgresql"
22 include "profile::apache"
23 include "profile::redis"
24 include "profile::monitoring"
26 ensure_packages(["python-pip", "python-virtualenv", "python-django"])
28 $caldance_app = "${home}/app"
29 $pg_password = generate_password(24, $password_seed, "postgres_caldance")
30 $secret_key = generate_password(24, $password_seed, "secret_key_caldance")
34 "DB_USER" => $pg_user,
35 "DB_PASSWORD" => $pg_password,
36 "DB_HOST" => $pg_hostname,
37 "DB_PORT" => $pg_port,
38 "SECRET_KEY" => $secret_key,
40 "LOG_FILE" => "$home/caldev_django.log",
41 "FROM_EMAIL" => $mail_from,
42 "EMAIL_HOST" => $smtp_host,
43 "EMAIL_PORT" => $smtp_port,
45 $shell_env = $environment.map |$key, $value| { "$key=$value" }
46 $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" }
51 file { "${home}/caldev_django.log":
58 ensure => "directory",
62 require => User["$user:"],
65 exec { "initialize_venv":
67 require => User["$user:"],
68 command => "/usr/bin/virtualenv ${home}/virtualenv",
69 creates => "${home}/virtualenv",
72 archive { "${home}/caldance_${caldance_version}.tar.gz":
73 path => "${home}/caldance_${caldance_version}.tar.gz",
74 source => "https://release.immae.eu/caldance/caldance_${caldance_version}.tar.gz",
75 checksum_type => "sha256",
76 checksum => $caldance_sha256,
80 username => lookup("base_installation::ldap_cn"),
81 password => generate_password(24, $password_seed, "ldap"),
82 extract_path => $caldance_app,
83 require => [User["$user:"], File[$caldance_app]],
85 exec { "py-requirements":
88 environment => concat(["HOME=${home}"], $shell_env),
89 command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt",
90 require => User["$user:"],
96 environment => concat(["HOME=${home}"], $shell_env),
97 command => "$caldance_app/manage.py migrate",
98 require => [User["$user:"], File["$caldance_app/manage.py"]],
102 cwd => $caldance_app,
104 environment => concat(["HOME=${home}"], $shell_env),
105 command => "$caldance_app/manage.py collectstatic --no-input",
106 require => [User["$user:"], File["$caldance_app/manage.py"]],
109 exec { "reload httpd":
110 command => "/usr/bin/systemctl reload httpd",
111 require => [User["$user:"], File["$caldance_app/manage.py"]],
115 $python_path = "${home}/virtualenv/bin/python"
116 file { "$caldance_app/manage.py":
120 content => template("role/caldance/manage.py.erb"),
123 Archive[ "${home}/caldance_${caldance_version}.tar.gz"],
127 profile::postgresql::master { "postgresql master for caldance":
128 letsencrypt_host => $web_host,
129 backup_hosts => ["backup-1"],
132 postgresql::server::db { $pg_db:
134 password => postgresql_password($pg_user, $pg_password),
137 # pour le script de génération de mdp
138 ensure_packages(["perl-digest-sha1"])
140 ensure_packages(["postgis", "python-gdal", "ripgrep"])
141 file { "/usr/local/bin/ldap_ssha":
145 source => "puppet:///modules/base_installation/scripts/ldap_ssha",
146 require => Package["perl-digest-sha1"],
149 sudo::conf { 'wheel_nopasswd':
151 content => "%wheel ALL=(ALL) NOPASSWD: ALL",
152 require => Package["sudo"],
155 ensure_packages(["mod_wsgi"])
156 class { 'apache::mod::wsgi':
157 wsgi_python_home => "${home}/virtualenv",
158 wsgi_python_path => $caldance_app,
159 require => Package["mod_wsgi"],
161 class { 'apache::mod::authn_file': }
162 class { 'apache::mod::authn_core': }
163 class { 'apache::mod::authz_user': }
164 class { 'apache::mod::auth_basic': }
166 apache::vhost { $web_host:
169 manage_docroot => false,
171 ssl_cert => "/etc/letsencrypt/live/$web_host/cert.pem",
172 ssl_key => "/etc/letsencrypt/live/$web_host/privkey.pem",
173 ssl_chain => "/etc/letsencrypt/live/$web_host/chain.pem",
174 require => Letsencrypt::Certonly[$web_host],
177 path => "$caldance_app/main_app",
178 require => "all granted",
181 path => "$caldance_app/www/static",
182 require => "all granted",
186 provider => "location",
187 require => "valid-user",
188 auth_type => "Basic",
189 auth_name => "Authentification requise",
190 auth_user_file => "$web_home/caldev/.htpasswd",
196 path => "$caldance_app/www/static/",
199 setenv => $apache_env,
200 wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" };
201 default: * => $::profile::apache::apache_vhost_default;