{"size": 1024, "ext": "js", "max_stars_repo_path": "lib/bakelets/config/template.js", "max_stars_repo_name": "ssmirr/Baker", "max_stars_repo_stars_event_min_datetime": "2018-08-16T11:38:15.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-11T20:35:09.000Z", "max_issues_repo_path": "lib/bakelets/config/template.js", "max_issues_repo_name": "ssmirr/Baker", "max_issues_repo_issues_event_min_datetime": "2018-08-18T04:56:29.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-31T22:30:52.000Z", "max_forks_repo_path": "lib/bakelets/config/template.js", "max_forks_repo_name": "ssmirr/Baker", "max_forks_repo_forks_event_min_datetime": "2018-09-14T11:58:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-27T22:21:49.000Z"}
{"max_stars_count": 182, "max_issues_count": 123, "max_forks_count": 14, "avg_line_length": 25.6, "max_line_length": 103, "alphanum_fraction": 0.60546875}
const Bakelet = require('../bakelet');
const Ansible = require('../../modules/configuration/ansible');
const path    = require('path');
const Ssh     = require('../../modules/ssh');

class Template extends Bakelet {

    constructor(name,ansibleSSHConfig, version) {
        super(ansibleSSHConfig);

        this.name = name;
        this.version = version;
    }

    async load(obj, variables)
    {
        await Ssh.copyFromHostToVM(
            path.resolve(this.bakePath, obj.template.src),
            `/home/vagrant/baker/${this.name}/templates/`,
            this.ansibleSSHConfig,
            false
        );

        this.src = `templates/${path.basename(path.resolve(this.bakePath, obj.template.src))}`;
        this.dest = obj.template.dest;
        this.variables = variables;
    }

    async install()
    {
        await Ansible.runAnsibleTemplateCmd(
            {name: this.name}, this.src, this.dest, this.variables, this.ansibleSSHConfig, this.verbose
        );
    }

}

module.exports = Template;

