]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - modules/role/manifests/cryptoportfolio/bot.pp
Rename trader variable
[perso/Immae/Projets/Puppet.git] / modules / role / manifests / cryptoportfolio / bot.pp
1 class role::cryptoportfolio::bot inherits role::cryptoportfolio {
2 $password_seed = lookup("base_installation::puppet_pass_seed")
3
4 $cf_bot_app = "${home}/bot"
5 $cf_bot_app_conf = "${home}/bot_config.ini"
6 $cf_bot_app_reports = "${home}/bot_reports"
7
8 ensure_packages(["python", "python-pip"])
9
10 file { $cf_bot_app:
11 ensure => "directory",
12 mode => "0700",
13 owner => $user,
14 group => $group,
15 require => User["$user:"],
16 }
17
18 archive { "${home}/trader_${trader_version}.tar.gz":
19 path => "${home}/trader_${trader_version}.tar.gz",
20 source => "https://git.immae.eu/releases/cryptoportfolio/trader/trader_${trader_version}.tar.gz",
21 checksum_type => "sha256",
22 checksum => $trader_sha256,
23 cleanup => false,
24 extract => true,
25 user => $user,
26 username => lookup("base_installation::ldap_cn"),
27 password => generate_password(24, $password_seed, "ldap"),
28 extract_path => $cf_bot_app,
29 require => [User["$user:"], File[$cf_bot_app]],
30 } ~>
31 exec { "py-cryptoportfolio-dependencies":
32 cwd => $cf_bot_app,
33 user => $user,
34 environment => ["HOME=${home}"],
35 command => "/usr/bin/make install",
36 require => User["$user:"],
37 refreshonly => true,
38 before => [
39 File[$cf_bot_app_conf],
40 Cron::Job::Multiple["py-cryptoportfolio"],
41 ]
42 }
43
44 $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio")
45 file { $cf_bot_app_conf:
46 owner => $user,
47 group => $group,
48 mode => "0600",
49 content => template("role/cryptoportfolio/bot_config.ini.erb"),
50 require => [
51 User["$user:"],
52 Archive["${home}/trader_${trader_version}.tar.gz"],
53 ],
54 }
55
56 cron::job::multiple { "py-cryptoportfolio":
57 ensure => present,
58 environment => ["HOME=${home}","PATH=/usr/bin/","CRON_TZ=UTC"],
59 require => [
60 File[$cf_bot_app_conf],
61 Archive["${home}/trader_${trader_version}.tar.gz"]
62 ],
63 jobs => [
64 {
65 command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --before",
66 user => $user,
67 weekday => 7, # Sunday
68 hour => 22,
69 minute => 30,
70 description => "Run before the cryptoportfolio update",
71 },
72 {
73 command => "cd $cf_bot_app ; python main.py --quiet --config $cf_bot_app_conf --after",
74 user => $user,
75 weekday => 1, # Monday
76 hour => 0,
77 minute => 0,
78 description => "Run after the cryptoportfolio update",
79 }
80 ],
81 }
82
83 unless empty($webhook_url) {
84 exec { "bot-slack-notify":
85 refreshonly => true,
86 environment => [
87 "P_PROJECT=Trader",
88 "P_WEBHOOK=${webhook_url}",
89 "P_VERSION=${trader_version}",
90 "P_HOST=${web_host}",
91 "P_HTTPS=${web_ssl}",
92 ],
93 command => "/usr/local/bin/slack-notify",
94 require => File["/usr/local/bin/slack-notify"],
95 subscribe => Exec["py-cryptoportfolio-dependencies"],
96 }
97 }
98 }
99