]>
Commit | Line | Data |
---|---|---|
851ca3c6 | 1 | class role::caldance ( |
a25b5f82 IB |
2 | String $user, |
3 | String $group, | |
4 | String $home, | |
5 | String $web_host, | |
6 | String $pg_user, | |
7 | String $pg_db, | |
8 | String $mail_from, | |
9 | String $smtp_host, | |
10 | String $smtp_port, | |
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, | |
851ca3c6 | 15 | ) { |
a25b5f82 | 16 | $password_seed = lookup("base_installation::puppet_pass_seed") |
851ca3c6 IB |
17 | include "base_installation" |
18 | ||
19 | include "profile::tools" | |
20 | include "profile::postgresql" | |
21 | include "profile::apache" | |
22 | include "profile::redis" | |
d8f933bd | 23 | include "profile::monitoring" |
851ca3c6 IB |
24 | |
25 | ensure_packages(["python-pip", "python-virtualenv", "python-django"]) | |
b3ac23bb | 26 | |
a25b5f82 | 27 | $caldance_app = "${home}/app" |
d3948290 IB |
28 | $pg_password = generate_password(24, $password_seed, "postgres_caldance") |
29 | $secret_key = generate_password(24, $password_seed, "secret_key_caldance") | |
30 | ||
31 | $environment = { | |
32 | "DB_NAME" => $pg_db, | |
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, | |
38 | "DEBUG" => "False", | |
39 | "LOG_FILE" => "$home/caldev_django.log", | |
40 | "FROM_EMAIL" => $mail_from, | |
41 | "EMAIL_HOST" => $smtp_host, | |
42 | "EMAIL_PORT" => $smtp_port, | |
43 | } | |
44 | $shell_env = $environment.map |$key, $value| { "$key=$value" } | |
45 | $apache_env = $environment.map |$key, $value| { "CALDANCE_$key $value" } | |
46 | ||
47 | file { $home: | |
48 | mode => "0755", | |
49 | } | |
50 | file { "${home}/caldev_django.log": | |
51 | mode => "0664", | |
52 | owner => $user, | |
53 | group => "http", | |
d3948290 | 54 | } |
a25b5f82 IB |
55 | |
56 | file { $caldance_app: | |
57 | ensure => "directory", | |
58 | mode => "0755", | |
59 | owner => $user, | |
60 | group => $group, | |
61 | require => User["$user:"], | |
62 | } | |
63 | ||
64 | exec { "initialize_venv": | |
65 | user => $user, | |
66 | require => User["$user:"], | |
67 | command => "/usr/bin/virtualenv ${home}/virtualenv", | |
68 | creates => "${home}/virtualenv", | |
69 | } | |
70 | -> | |
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, | |
76 | cleanup => false, | |
77 | extract => true, | |
78 | user => $user, | |
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]], | |
83 | } ~> | |
84 | exec { "py-requirements": | |
85 | cwd => $caldance_app, | |
86 | user => $user, | |
d3948290 | 87 | environment => concat(["HOME=${home}"], $shell_env), |
f22a16c8 | 88 | command => "/usr/bin/sed -i -e '/GDAL/d' requirements.txt && ${home}/virtualenv/bin/pip install -r requirements.txt --upgrade", |
a25b5f82 IB |
89 | require => User["$user:"], |
90 | refreshonly => true, | |
91 | } ~> | |
92 | exec { "py-migrate": | |
93 | cwd => $caldance_app, | |
94 | user => $user, | |
d3948290 | 95 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 96 | command => "$caldance_app/manage.py migrate", |
d3948290 | 97 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
98 | refreshonly => true, |
99 | } ~> | |
100 | exec { "py-static": | |
101 | cwd => $caldance_app, | |
102 | user => $user, | |
d3948290 | 103 | environment => concat(["HOME=${home}"], $shell_env), |
a25b5f82 | 104 | command => "$caldance_app/manage.py collectstatic --no-input", |
d3948290 | 105 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
106 | refreshonly => true, |
107 | } ~> | |
108 | exec { "reload httpd": | |
109 | command => "/usr/bin/systemctl reload httpd", | |
d3948290 | 110 | require => [User["$user:"], File["$caldance_app/manage.py"]], |
a25b5f82 IB |
111 | refreshonly => true, |
112 | } | |
113 | ||
a25b5f82 IB |
114 | $python_path = "${home}/virtualenv/bin/python" |
115 | file { "$caldance_app/manage.py": | |
116 | owner => $user, | |
117 | group => $group, | |
118 | mode => "0755", | |
119 | content => template("role/caldance/manage.py.erb"), | |
120 | require => [ | |
121 | User["$user:"], | |
122 | Archive[ "${home}/caldance_${caldance_version}.tar.gz"], | |
123 | ], | |
124 | } | |
125 | ||
126 | profile::postgresql::master { "postgresql master for caldance": | |
127 | letsencrypt_host => $web_host, | |
128 | backup_hosts => ["backup-1"], | |
129 | } | |
130 | ||
131 | postgresql::server::db { $pg_db: | |
132 | user => $pg_user, | |
133 | password => postgresql_password($pg_user, $pg_password), | |
134 | } | |
135 | ||
b3ac23bb IB |
136 | # pour le script de génération de mdp |
137 | ensure_packages(["perl-digest-sha1"]) | |
138 | ||
a25b5f82 | 139 | ensure_packages(["postgis", "python-gdal", "ripgrep"]) |
b3ac23bb IB |
140 | file { "/usr/local/bin/ldap_ssha": |
141 | owner => "root", | |
142 | group => "root", | |
143 | mode => "0755", | |
144 | source => "puppet:///modules/base_installation/scripts/ldap_ssha", | |
145 | require => Package["perl-digest-sha1"], | |
146 | } | |
a25b5f82 IB |
147 | |
148 | sudo::conf { 'wheel_nopasswd': | |
149 | priority => 99, | |
150 | content => "%wheel ALL=(ALL) NOPASSWD: ALL", | |
151 | require => Package["sudo"], | |
152 | } | |
153 | ||
154 | ensure_packages(["mod_wsgi"]) | |
155 | class { 'apache::mod::wsgi': | |
d3948290 IB |
156 | wsgi_python_home => "${home}/virtualenv", |
157 | wsgi_python_path => $caldance_app, | |
a25b5f82 IB |
158 | require => Package["mod_wsgi"], |
159 | } | |
160 | class { 'apache::mod::authn_file': } | |
161 | class { 'apache::mod::authn_core': } | |
162 | class { 'apache::mod::authz_user': } | |
163 | class { 'apache::mod::auth_basic': } | |
164 | ||
165 | apache::vhost { $web_host: | |
166 | port => '443', | |
167 | docroot => false, | |
168 | manage_docroot => false, | |
169 | ssl => true, | |
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], | |
174 | directories => [ | |
175 | { | |
d3948290 | 176 | path => "$caldance_app/main_app", |
a25b5f82 IB |
177 | require => "all granted", |
178 | }, | |
179 | { | |
d3948290 | 180 | path => "$caldance_app/www/static", |
a25b5f82 IB |
181 | require => "all granted", |
182 | }, | |
183 | { | |
184 | path => "/", | |
185 | provider => "location", | |
186 | require => "valid-user", | |
187 | auth_type => "Basic", | |
188 | auth_name => "Authentification requise", | |
b1072a47 | 189 | auth_user_file => "$home/htpasswd", |
a25b5f82 IB |
190 | }, |
191 | ], | |
192 | aliases => [ | |
193 | { | |
194 | alias => "/static/", | |
d3948290 | 195 | path => "$caldance_app/www/static/", |
a25b5f82 IB |
196 | }, |
197 | ], | |
d3948290 IB |
198 | setenv => $apache_env, |
199 | wsgi_script_aliases => { "/" => "$caldance_app/main_app/wsgi.py" }; | |
a25b5f82 IB |
200 | default: * => $::profile::apache::apache_vhost_default; |
201 | } | |
851ca3c6 | 202 | } |