class role::cryptoportfolio::bot inherits role::cryptoportfolio { $password_seed = lookup("base_installation::puppet_pass_seed") $cf_bot_app = "${home}/bot" $cf_bot_app_conf = "${home}/bot_config.ini" $cf_bot_app_reports = "${home}/bot_reports" ensure_packages(["python", "python-pip"]) file { $cf_bot_app: ensure => "directory", mode => "0700", owner => $user, group => $group, require => User["$user:"], } archive { "${home}/trader_${bot_version}.tar.gz": path => "${home}/trader_${bot_version}.tar.gz", source => "https://git.immae.eu/releases/cryptoportfolio/trader/trader_${bot_version}.tar.gz", checksum_type => "sha256", checksum => $bot_sha256, cleanup => false, extract => true, user => $user, username => lookup("base_installation::ldap_cn"), password => generate_password(24, $password_seed, "ldap"), extract_path => $cf_bot_app, require => [User["$user:"], File[$cf_bot_app]], } ~> exec { "py-cryptoportfolio-dependencies": cwd => $cf_bot_app, user => $user, environment => ["HOME=${home}"], command => "/usr/bin/make install", require => User["$user:"], refreshonly => true, before => [ File[$cf_bot_app_conf], Cron["py-cryptoportfolio-before"], Cron["py-cryptoportfolio-after"], ] } $pg_password = generate_password(24, $password_seed, "postgres_cryptoportfolio") file { $cf_bot_app_conf: owner => $user, group => $group, mode => "0600", content => template("role/cryptoportfolio/bot_config.ini.erb"), require => [ User["$user:"], Archive["${home}/trader_${bot_version}.tar.gz"], ], } cron { "py-cryptoportfolio-before": ensure => present, command => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf --before", user => $user, weekday => 7, # Sunday hour => 22, minute => 30, environment => ["HOME=${home}","PATH=/usr/bin/"], require => [ File[$cf_bot_app_conf], Archive["${home}/trader_${bot_version}.tar.gz"] ], } cron { "py-cryptoportfolio-after": ensure => present, command => "cd $cf_bot_app ; python main.py --config $cf_bot_app_conf --after", user => $user, weekday => 1, # Monday hour => 1, minute => 0, environment => ["HOME=${home}","PATH=/usr/bin/"], require => [ File[$cf_bot_app_conf], Archive["${home}/trader_${bot_version}.tar.gz"] ], } unless empty($webhook_url) { exec { "bot-slack-notify": refreshonly => true, environment => [ "P_PROJECT=Trader", "P_WEBHOOK=${webhook_url}", "P_VERSION=${bot_version}", "P_HOST=${web_host}", "P_HTTPS=${web_ssl}", ], command => "/usr/local/bin/slack-notify", require => File["/usr/local/bin/slack-notify"], subscribe => Exec["py-cryptoportfolio-dependencies"], } } }