示例#1
0
//	Convert {{role}} in task.yml to array of individual role with 'all' role
//	When role is 'web,ap', convert from 'role[{{role}}_deploy]' to role[all_deploy], role[web_deploy] and role[ap_deploy]
func (o *ChefOperation) parseRunList(runlist []string, vars map[string]string) []string {
	var results []string
	for _, v := range runlist {
		if strings.Contains(v, "{{role}}") {
			roles := append([]string{"all"}, strings.Split(config.Role, ",")...)
			for _, role := range roles {
				results = append(results, strings.Replace(v, "{{role}}", role, -1))
			}
		} else {
			results = append(results, v)
		}
	}
	return util.ParseArray(results, vars)
}
示例#2
0
func (o *ChefOperation) Run(vars map[string]string) error {
	//	Filter runlist by JSON file existance in roles directory
	runlist := o.ensureRunList(o.parseRunList(o.RunList, vars))

	//	Create attributes JSON for chef-solo
	json, err := o.createJson(runlist, util.ParseArray(o.AttributeKeys, vars), util.ParseMap(o.Attributes, vars))
	if err != nil {
		return err
	}

	//	Create configuration file for chef-solo
	conf, err := o.createConf(vars)
	if err != nil {
		return err
	}

	//	Execute berkshelf to get depencency cookbooks
	if err := o.executeBerkshelf(); err != nil {
		return err
	}

	//	Execute chef-solo with configuration file and attribute JSON
	return o.executeChef(conf, json)
}