2019-10-14 10:43:59 -04:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
// This package implements a provisioner for Packer that uses
|
|
|
|
// Chef to provision the remote machine, specifically with chef-client (that is,
|
|
|
|
// with a Chef server).
|
|
|
|
package chefclient
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-03-19 13:11:19 -04:00
|
|
|
"context"
|
2014-01-24 20:06:55 -05:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2014-02-24 11:53:56 -05:00
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-12 17:44:02 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/common"
|
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/guestexec"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2020-11-18 13:34:59 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/config"
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2020-11-12 17:44:02 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/uuid"
|
2014-01-24 20:06:55 -05:00
|
|
|
)
|
|
|
|
|
2015-08-20 16:27:51 -04:00
|
|
|
type guestOSTypeConfig struct {
|
|
|
|
executeCommand string
|
|
|
|
installCommand string
|
2016-06-14 14:34:25 -04:00
|
|
|
knifeCommand string
|
2015-08-20 16:27:51 -04:00
|
|
|
stagingDir string
|
|
|
|
}
|
|
|
|
|
|
|
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
2020-11-09 06:16:44 -05:00
|
|
|
guestexec.UnixOSType: {
|
2015-08-20 16:27:51 -04:00
|
|
|
executeCommand: "{{if .Sudo}}sudo {{end}}chef-client --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
2019-12-09 14:17:04 -05:00
|
|
|
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
2016-06-14 14:34:25 -04:00
|
|
|
knifeCommand: "{{if .Sudo}}sudo {{end}}knife {{.Args}} {{.Flags}}",
|
2015-08-20 16:27:51 -04:00
|
|
|
stagingDir: "/tmp/packer-chef-client",
|
|
|
|
},
|
2020-11-09 06:16:44 -05:00
|
|
|
guestexec.WindowsOSType: {
|
2015-08-20 16:27:51 -04:00
|
|
|
executeCommand: "c:/opscode/chef/bin/chef-client.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
2019-12-09 14:17:04 -05:00
|
|
|
installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
|
2016-06-14 14:34:25 -04:00
|
|
|
knifeCommand: "c:/opscode/chef/bin/knife.bat {{.Args}} {{.Flags}}",
|
2015-08-20 16:27:51 -04:00
|
|
|
stagingDir: "C:/Windows/Temp/packer-chef-client",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
|
2016-01-28 17:55:17 -05:00
|
|
|
Json map[string]interface{}
|
|
|
|
|
|
|
|
ChefEnvironment string `mapstructure:"chef_environment"`
|
2019-05-17 11:19:22 -04:00
|
|
|
ChefLicense string `mapstructure:"chef_license"`
|
2016-01-28 17:55:17 -05:00
|
|
|
ClientKey string `mapstructure:"client_key"`
|
|
|
|
ConfigTemplate string `mapstructure:"config_template"`
|
2018-12-13 05:25:12 -05:00
|
|
|
ElevatedUser string `mapstructure:"elevated_user"`
|
|
|
|
ElevatedPassword string `mapstructure:"elevated_password"`
|
2016-01-28 17:55:17 -05:00
|
|
|
EncryptedDataBagSecretPath string `mapstructure:"encrypted_data_bag_secret_path"`
|
|
|
|
ExecuteCommand string `mapstructure:"execute_command"`
|
|
|
|
GuestOSType string `mapstructure:"guest_os_type"`
|
|
|
|
InstallCommand string `mapstructure:"install_command"`
|
2016-06-14 14:34:25 -04:00
|
|
|
KnifeCommand string `mapstructure:"knife_command"`
|
2015-08-21 18:06:24 -04:00
|
|
|
NodeName string `mapstructure:"node_name"`
|
2018-01-31 11:54:40 -05:00
|
|
|
PolicyGroup string `mapstructure:"policy_group"`
|
|
|
|
PolicyName string `mapstructure:"policy_name"`
|
2015-08-21 18:06:24 -04:00
|
|
|
PreventSudo bool `mapstructure:"prevent_sudo"`
|
|
|
|
RunList []string `mapstructure:"run_list"`
|
|
|
|
ServerUrl string `mapstructure:"server_url"`
|
|
|
|
SkipCleanClient bool `mapstructure:"skip_clean_client"`
|
|
|
|
SkipCleanNode bool `mapstructure:"skip_clean_node"`
|
2016-12-19 15:16:37 -05:00
|
|
|
SkipCleanStagingDirectory bool `mapstructure:"skip_clean_staging_directory"`
|
2015-08-21 18:06:24 -04:00
|
|
|
SkipInstall bool `mapstructure:"skip_install"`
|
2016-01-28 17:55:17 -05:00
|
|
|
SslVerifyMode string `mapstructure:"ssl_verify_mode"`
|
2018-01-12 17:53:49 -05:00
|
|
|
TrustedCertsDir string `mapstructure:"trusted_certs_dir"`
|
2015-08-21 18:06:24 -04:00
|
|
|
StagingDir string `mapstructure:"staging_directory"`
|
|
|
|
ValidationClientName string `mapstructure:"validation_client_name"`
|
2016-01-28 17:55:17 -05:00
|
|
|
ValidationKeyPath string `mapstructure:"validation_key_path"`
|
2019-12-09 14:17:04 -05:00
|
|
|
Version string `mapstructure:"version"`
|
2014-01-24 20:06:55 -05:00
|
|
|
|
2015-05-27 17:41:47 -04:00
|
|
|
ctx interpolate.Context
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Provisioner struct {
|
2015-08-20 16:27:51 -04:00
|
|
|
config Config
|
2020-11-19 18:10:00 -05:00
|
|
|
communicator packersdk.Communicator
|
2015-08-20 16:27:51 -04:00
|
|
|
guestOSTypeConfig guestOSTypeConfig
|
2020-11-09 06:16:44 -05:00
|
|
|
guestCommands *guestexec.GuestCommands
|
2019-12-12 19:42:53 -05:00
|
|
|
generatedData map[string]interface{}
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigTemplate struct {
|
2016-01-28 17:55:17 -05:00
|
|
|
ChefEnvironment string
|
2019-05-17 11:19:22 -04:00
|
|
|
ChefLicense string
|
2016-01-28 17:55:17 -05:00
|
|
|
ClientKey string
|
2015-08-20 16:27:51 -04:00
|
|
|
EncryptedDataBagSecretPath string
|
2016-01-28 17:55:17 -05:00
|
|
|
NodeName string
|
2018-01-31 11:54:40 -05:00
|
|
|
PolicyGroup string
|
|
|
|
PolicyName string
|
2016-01-28 17:55:17 -05:00
|
|
|
ServerUrl string
|
|
|
|
SslVerifyMode string
|
2018-01-12 17:53:49 -05:00
|
|
|
TrustedCertsDir string
|
2016-01-28 17:55:17 -05:00
|
|
|
ValidationClientName string
|
|
|
|
ValidationKeyPath string
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type ExecuteTemplate struct {
|
|
|
|
ConfigPath string
|
|
|
|
JsonPath string
|
|
|
|
Sudo bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type InstallChefTemplate struct {
|
2019-12-09 14:17:04 -05:00
|
|
|
Sudo bool
|
|
|
|
Version string
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
2016-06-14 14:42:53 -04:00
|
|
|
type KnifeTemplate struct {
|
2016-09-29 17:13:04 -04:00
|
|
|
Sudo bool
|
|
|
|
Flags string
|
|
|
|
Args string
|
2016-06-14 14:34:25 -04:00
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
2015-05-27 17:41:47 -04:00
|
|
|
err := config.Decode(&p.config, &config.DecodeOpts{
|
2020-10-09 20:01:55 -04:00
|
|
|
PluginType: "chef-client",
|
2015-06-22 15:26:54 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &p.config.ctx,
|
2015-05-27 17:41:47 -04:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"execute_command",
|
|
|
|
"install_command",
|
2016-06-14 14:34:25 -04:00
|
|
|
"knife_command",
|
2015-05-27 17:41:47 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-20 16:27:51 -04:00
|
|
|
if p.config.GuestOSType == "" {
|
2020-11-09 06:16:44 -05:00
|
|
|
p.config.GuestOSType = guestexec.DefaultOSType
|
2015-08-20 16:27:51 -04:00
|
|
|
}
|
|
|
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
|
|
|
|
|
|
|
var ok bool
|
|
|
|
p.guestOSTypeConfig, ok = guestOSTypeConfigs[p.config.GuestOSType]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
|
|
|
}
|
|
|
|
|
2020-11-09 06:16:44 -05:00
|
|
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
2015-08-20 16:27:51 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
|
|
|
}
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
if p.config.ExecuteCommand == "" {
|
2015-08-20 16:27:51 -04:00
|
|
|
p.config.ExecuteCommand = p.guestOSTypeConfig.executeCommand
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.config.InstallCommand == "" {
|
2015-08-20 16:27:51 -04:00
|
|
|
p.config.InstallCommand = p.guestOSTypeConfig.installCommand
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.config.RunList == nil {
|
|
|
|
p.config.RunList = make([]string, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.config.StagingDir == "" {
|
2015-08-20 16:27:51 -04:00
|
|
|
p.config.StagingDir = p.guestOSTypeConfig.stagingDir
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
2016-06-14 14:34:25 -04:00
|
|
|
if p.config.KnifeCommand == "" {
|
|
|
|
p.config.KnifeCommand = p.guestOSTypeConfig.knifeCommand
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:07:02 -05:00
|
|
|
var errs *packersdk.MultiError
|
2014-01-24 20:06:55 -05:00
|
|
|
if p.config.ConfigTemplate != "" {
|
|
|
|
fi, err := os.Stat(p.config.ConfigTemplate)
|
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-01-24 20:06:55 -05:00
|
|
|
errs, fmt.Errorf("Bad config template path: %s", err))
|
|
|
|
} else if fi.IsDir() {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-01-24 20:06:55 -05:00
|
|
|
errs, fmt.Errorf("Config template path must be a file: %s", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 12:45:04 -05:00
|
|
|
if p.config.ServerUrl == "" {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-02-24 12:45:04 -05:00
|
|
|
errs, fmt.Errorf("server_url must be set"))
|
|
|
|
}
|
|
|
|
|
2019-05-21 09:26:07 -04:00
|
|
|
if p.config.SkipInstall == false && p.config.InstallCommand == p.guestOSTypeConfig.installCommand {
|
|
|
|
if p.config.ChefLicense == "" {
|
|
|
|
p.config.ChefLicense = "accept-silent"
|
|
|
|
}
|
2019-05-17 11:19:22 -04:00
|
|
|
}
|
|
|
|
|
2015-08-21 18:06:24 -04:00
|
|
|
if p.config.EncryptedDataBagSecretPath != "" {
|
|
|
|
pFileInfo, err := os.Stat(p.config.EncryptedDataBagSecretPath)
|
|
|
|
|
|
|
|
if err != nil || pFileInfo.IsDir() {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2015-08-21 18:06:24 -04:00
|
|
|
errs, fmt.Errorf("Bad encrypted data bag secret '%s': %s", p.config.EncryptedDataBagSecretPath, err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 16:08:25 -05:00
|
|
|
if (p.config.PolicyName != "") != (p.config.PolicyGroup != "") {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("If either policy_name or policy_group are set, they must both be set."))
|
2018-01-31 16:08:25 -05:00
|
|
|
}
|
|
|
|
|
2014-05-01 11:48:04 -04:00
|
|
|
jsonValid := true
|
|
|
|
for k, v := range p.config.Json {
|
|
|
|
p.config.Json[k], err = p.deepJsonFix(k, v)
|
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-05-01 11:48:04 -04:00
|
|
|
errs, fmt.Errorf("Error processing JSON: %s", err))
|
|
|
|
jsonValid = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if jsonValid {
|
|
|
|
// Process the user variables within the JSON and set the JSON.
|
|
|
|
// Do this early so that we can validate and show errors.
|
|
|
|
p.config.Json, err = p.processJsonUserVars()
|
|
|
|
if err != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(
|
2014-05-01 11:48:04 -04:00
|
|
|
errs, fmt.Errorf("Error processing user variables in JSON: %s", err))
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error {
|
2019-12-12 19:42:53 -05:00
|
|
|
p.generatedData = generatedData
|
2018-12-13 05:25:12 -05:00
|
|
|
p.communicator = comm
|
|
|
|
|
2014-02-24 12:45:04 -05:00
|
|
|
nodeName := p.config.NodeName
|
2014-09-24 14:19:28 -04:00
|
|
|
if nodeName == "" {
|
|
|
|
nodeName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
|
|
|
|
}
|
2014-02-24 12:45:04 -05:00
|
|
|
remoteValidationKeyPath := ""
|
|
|
|
serverUrl := p.config.ServerUrl
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
if !p.config.SkipInstall {
|
2019-12-09 14:17:04 -05:00
|
|
|
if err := p.installChef(ui, comm, p.config.Version); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return fmt.Errorf("Error installing Chef: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.createDir(ui, comm, p.config.StagingDir); err != nil {
|
|
|
|
return fmt.Errorf("Error creating staging directory: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-04-09 02:15:16 -04:00
|
|
|
if p.config.ClientKey == "" {
|
|
|
|
p.config.ClientKey = fmt.Sprintf("%s/client.pem", p.config.StagingDir)
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:06:24 -04:00
|
|
|
encryptedDataBagSecretPath := ""
|
|
|
|
if p.config.EncryptedDataBagSecretPath != "" {
|
|
|
|
encryptedDataBagSecretPath = fmt.Sprintf("%s/encrypted_data_bag_secret", p.config.StagingDir)
|
2016-01-28 17:55:17 -05:00
|
|
|
if err := p.uploadFile(ui,
|
|
|
|
comm,
|
|
|
|
encryptedDataBagSecretPath,
|
|
|
|
p.config.EncryptedDataBagSecretPath); err != nil {
|
2015-08-21 18:06:24 -04:00
|
|
|
return fmt.Errorf("Error uploading encrypted data bag secret: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 22:21:27 -04:00
|
|
|
|
|
|
|
if p.config.ValidationKeyPath != "" {
|
2020-01-28 08:33:42 -05:00
|
|
|
path, err := packer.ExpandUser(p.config.ValidationKeyPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error while expanding a tilde in the validation key: %s", err)
|
|
|
|
}
|
2016-04-29 22:21:27 -04:00
|
|
|
remoteValidationKeyPath = fmt.Sprintf("%s/validation.pem", p.config.StagingDir)
|
2020-01-28 08:33:42 -05:00
|
|
|
if err := p.uploadFile(ui, comm, remoteValidationKeyPath, path); err != nil {
|
2016-04-29 22:21:27 -04:00
|
|
|
return fmt.Errorf("Error copying validation key: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 12:45:04 -05:00
|
|
|
configPath, err := p.createConfig(
|
2016-01-28 17:55:17 -05:00
|
|
|
ui,
|
|
|
|
comm,
|
|
|
|
nodeName,
|
|
|
|
serverUrl,
|
|
|
|
p.config.ClientKey,
|
2019-05-17 11:19:22 -04:00
|
|
|
p.config.ChefLicense,
|
2016-01-28 17:55:17 -05:00
|
|
|
encryptedDataBagSecretPath,
|
|
|
|
remoteValidationKeyPath,
|
|
|
|
p.config.ValidationClientName,
|
|
|
|
p.config.ChefEnvironment,
|
2018-01-31 11:54:40 -05:00
|
|
|
p.config.PolicyGroup,
|
|
|
|
p.config.PolicyName,
|
2018-01-12 17:53:49 -05:00
|
|
|
p.config.SslVerifyMode,
|
|
|
|
p.config.TrustedCertsDir)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating Chef config file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonPath, err := p.createJson(ui, comm)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error creating JSON attributes: %s", err)
|
|
|
|
}
|
|
|
|
|
2014-02-24 11:53:56 -05:00
|
|
|
err = p.executeChef(ui, comm, configPath, jsonPath)
|
2015-06-24 07:46:59 -04:00
|
|
|
|
2017-02-10 02:37:35 -05:00
|
|
|
if !(p.config.SkipCleanNode && p.config.SkipCleanClient) {
|
|
|
|
|
|
|
|
knifeConfigPath, knifeErr := p.createKnifeConfig(
|
2018-01-12 17:53:49 -05:00
|
|
|
ui, comm, nodeName, serverUrl, p.config.ClientKey, p.config.SslVerifyMode, p.config.TrustedCertsDir)
|
2017-02-10 02:37:35 -05:00
|
|
|
|
|
|
|
if knifeErr != nil {
|
|
|
|
return fmt.Errorf("Error creating knife config on node: %s", knifeErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !p.config.SkipCleanNode {
|
|
|
|
if err := p.cleanNode(ui, comm, nodeName, knifeConfigPath); err != nil {
|
|
|
|
return fmt.Errorf("Error cleaning up chef node: %s", err)
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
2017-02-10 02:37:35 -05:00
|
|
|
if !p.config.SkipCleanClient {
|
|
|
|
if err := p.cleanClient(ui, comm, nodeName, knifeConfigPath); err != nil {
|
|
|
|
return fmt.Errorf("Error cleaning up chef client: %s", err)
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 11:53:56 -05:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error executing Chef: %s", err)
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
2016-12-19 15:16:37 -05:00
|
|
|
if !p.config.SkipCleanStagingDirectory {
|
|
|
|
if err := p.removeDir(ui, comm, p.config.StagingDir); err != nil {
|
|
|
|
return fmt.Errorf("Error removing %s: %s", p.config.StagingDir, err)
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) uploadFile(ui packersdk.Ui, comm packersdk.Communicator, remotePath string, localPath string) error {
|
2016-01-28 17:55:17 -05:00
|
|
|
ui.Message(fmt.Sprintf("Uploading %s...", localPath))
|
|
|
|
|
|
|
|
f, err := os.Open(localPath)
|
2015-08-21 18:06:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
2016-01-28 17:55:17 -05:00
|
|
|
return comm.Upload(remotePath, f, nil)
|
2015-08-21 18:06:24 -04:00
|
|
|
}
|
|
|
|
|
2016-01-28 17:55:17 -05:00
|
|
|
func (p *Provisioner) createConfig(
|
2020-11-19 14:54:31 -05:00
|
|
|
ui packersdk.Ui,
|
2020-11-19 18:10:00 -05:00
|
|
|
comm packersdk.Communicator,
|
2016-01-28 17:55:17 -05:00
|
|
|
nodeName string,
|
|
|
|
serverUrl string,
|
|
|
|
clientKey string,
|
2019-05-17 11:19:22 -04:00
|
|
|
chefLicense string,
|
2016-01-28 17:55:17 -05:00
|
|
|
encryptedDataBagSecretPath,
|
|
|
|
remoteKeyPath string,
|
|
|
|
validationClientName string,
|
|
|
|
chefEnvironment string,
|
2018-01-31 12:06:31 -05:00
|
|
|
policyGroup string,
|
|
|
|
policyName string,
|
2018-01-12 17:53:49 -05:00
|
|
|
sslVerifyMode string,
|
|
|
|
trustedCertsDir string) (string, error) {
|
2016-01-28 17:55:17 -05:00
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message("Creating configuration file 'client.rb'")
|
|
|
|
|
|
|
|
// Read the template
|
|
|
|
tpl := DefaultConfigTemplate
|
|
|
|
if p.config.ConfigTemplate != "" {
|
|
|
|
f, err := os.Open(p.config.ConfigTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
tplBytes, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
tpl = string(tplBytes)
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := p.config.ctx
|
|
|
|
ictx.Data = &ConfigTemplate{
|
2016-01-28 17:55:17 -05:00
|
|
|
NodeName: nodeName,
|
|
|
|
ServerUrl: serverUrl,
|
|
|
|
ClientKey: clientKey,
|
2019-05-17 11:19:22 -04:00
|
|
|
ChefLicense: chefLicense,
|
2016-01-28 17:55:17 -05:00
|
|
|
ValidationKeyPath: remoteKeyPath,
|
|
|
|
ValidationClientName: validationClientName,
|
|
|
|
ChefEnvironment: chefEnvironment,
|
2018-01-31 11:54:40 -05:00
|
|
|
PolicyGroup: policyGroup,
|
|
|
|
PolicyName: policyName,
|
2016-01-28 17:55:17 -05:00
|
|
|
SslVerifyMode: sslVerifyMode,
|
2018-01-12 17:53:49 -05:00
|
|
|
TrustedCertsDir: trustedCertsDir,
|
2015-08-20 16:27:51 -04:00
|
|
|
EncryptedDataBagSecretPath: encryptedDataBagSecretPath,
|
2015-05-27 17:41:47 -04:00
|
|
|
}
|
2019-03-29 11:50:02 -04:00
|
|
|
configString, err := interpolate.Render(tpl, &ictx)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:12:34 -04:00
|
|
|
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "client.rb"))
|
2014-05-10 00:03:35 -04:00
|
|
|
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString)), nil); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return remotePath, nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) createKnifeConfig(ui packersdk.Ui, comm packersdk.Communicator, nodeName string, serverUrl string, clientKey string, sslVerifyMode string, trustedCertsDir string) (string, error) {
|
2015-06-24 07:46:59 -04:00
|
|
|
ui.Message("Creating configuration file 'knife.rb'")
|
|
|
|
|
|
|
|
// Read the template
|
|
|
|
tpl := DefaultKnifeTemplate
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := p.config.ctx
|
|
|
|
ictx.Data = &ConfigTemplate{
|
2018-01-12 17:53:49 -05:00
|
|
|
NodeName: nodeName,
|
|
|
|
ServerUrl: serverUrl,
|
|
|
|
ClientKey: clientKey,
|
|
|
|
SslVerifyMode: sslVerifyMode,
|
|
|
|
TrustedCertsDir: trustedCertsDir,
|
2015-06-24 07:46:59 -04:00
|
|
|
}
|
2019-03-29 11:50:02 -04:00
|
|
|
configString, err := interpolate.Render(tpl, &ictx)
|
2015-06-24 07:46:59 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "knife.rb"))
|
|
|
|
if err := comm.Upload(remotePath, bytes.NewReader([]byte(configString)), nil); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return remotePath, nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) createJson(ui packersdk.Ui, comm packersdk.Communicator) (string, error) {
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message("Creating JSON attribute file")
|
|
|
|
|
|
|
|
jsonData := make(map[string]interface{})
|
|
|
|
|
|
|
|
// Copy the configured JSON
|
|
|
|
for k, v := range p.config.Json {
|
|
|
|
jsonData[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the run list if it was specified
|
|
|
|
if len(p.config.RunList) > 0 {
|
|
|
|
jsonData["run_list"] = p.config.RunList
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonBytes, err := json.MarshalIndent(jsonData, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Upload the bytes
|
2014-07-11 06:12:34 -04:00
|
|
|
remotePath := filepath.ToSlash(filepath.Join(p.config.StagingDir, "first-boot.json"))
|
2014-05-10 00:03:35 -04:00
|
|
|
if err := comm.Upload(remotePath, bytes.NewReader(jsonBytes), nil); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return remotePath, nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) createDir(ui packersdk.Ui, comm packersdk.Communicator, dir string) error {
|
2019-04-03 11:14:55 -04:00
|
|
|
ctx := context.TODO()
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message(fmt.Sprintf("Creating directory: %s", dir))
|
2014-11-03 22:15:58 -05:00
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd := &packersdk.RemoteCmd{Command: p.guestCommands.CreateDir(dir)}
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2015-06-15 16:37:20 -04:00
|
|
|
return err
|
|
|
|
}
|
2019-04-03 11:14:55 -04:00
|
|
|
if cmd.ExitStatus() != 0 {
|
2015-06-15 16:37:20 -04:00
|
|
|
return fmt.Errorf("Non-zero exit status. See output above for more info.")
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
2015-06-15 16:37:20 -04:00
|
|
|
// Chmod the directory to 0777 just so that we can access it as our user
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd = &packersdk.RemoteCmd{Command: p.guestCommands.Chmod(dir, "0777")}
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return err
|
|
|
|
}
|
2019-04-03 11:14:55 -04:00
|
|
|
if cmd.ExitStatus() != 0 {
|
2015-06-15 16:37:20 -04:00
|
|
|
return fmt.Errorf("Non-zero exit status. See output above for more info.")
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) cleanNode(ui packersdk.Ui, comm packersdk.Communicator, node string, knifeConfigPath string) error {
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Say("Cleaning up chef node...")
|
2015-06-15 17:29:12 -04:00
|
|
|
args := []string{"node", "delete", node}
|
2015-06-24 07:46:59 -04:00
|
|
|
if err := p.knifeExec(ui, comm, node, knifeConfigPath, args); err != nil {
|
2015-06-15 17:29:12 -04:00
|
|
|
return fmt.Errorf("Failed to cleanup node: %s", err)
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) cleanClient(ui packersdk.Ui, comm packersdk.Communicator, node string, knifeConfigPath string) error {
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Say("Cleaning up chef client...")
|
2015-06-15 17:29:12 -04:00
|
|
|
args := []string{"client", "delete", node}
|
2015-06-24 07:46:59 -04:00
|
|
|
if err := p.knifeExec(ui, comm, node, knifeConfigPath, args); err != nil {
|
2015-06-15 17:29:12 -04:00
|
|
|
return fmt.Errorf("Failed to cleanup client: %s", err)
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
|
2015-06-15 17:29:12 -04:00
|
|
|
return nil
|
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) knifeExec(ui packersdk.Ui, comm packersdk.Communicator, node string, knifeConfigPath string, args []string) error {
|
2015-06-15 17:29:12 -04:00
|
|
|
flags := []string{
|
|
|
|
"-y",
|
2015-06-24 07:46:59 -04:00
|
|
|
"-c", knifeConfigPath,
|
2015-06-15 17:29:12 -04:00
|
|
|
}
|
2019-04-03 11:14:55 -04:00
|
|
|
ctx := context.TODO()
|
2014-01-24 20:06:55 -05:00
|
|
|
|
2016-06-14 14:42:53 -04:00
|
|
|
p.config.ctx.Data = &KnifeTemplate{
|
2016-09-29 17:13:04 -04:00
|
|
|
Sudo: !p.config.PreventSudo,
|
2016-06-14 14:34:25 -04:00
|
|
|
Flags: strings.Join(flags, " "),
|
|
|
|
Args: strings.Join(args, " "),
|
|
|
|
}
|
|
|
|
|
|
|
|
command, err := interpolate.Render(p.config.KnifeCommand, &p.config.ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-06-15 17:29:12 -04:00
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd := &packersdk.RemoteCmd{Command: command}
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return err
|
|
|
|
}
|
2019-04-03 11:14:55 -04:00
|
|
|
if cmd.ExitStatus() != 0 {
|
2015-06-15 17:35:54 -04:00
|
|
|
return fmt.Errorf(
|
|
|
|
"Non-zero exit status. See output above for more info.\n\n"+
|
|
|
|
"Command: %s",
|
2016-06-14 14:34:25 -04:00
|
|
|
command)
|
2015-06-15 17:29:12 -04:00
|
|
|
}
|
2014-01-24 20:06:55 -05:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) removeDir(ui packersdk.Ui, comm packersdk.Communicator, dir string) error {
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message(fmt.Sprintf("Removing directory: %s", dir))
|
2019-04-03 11:14:55 -04:00
|
|
|
ctx := context.TODO()
|
2014-11-03 22:15:58 -05:00
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd := &packersdk.RemoteCmd{Command: p.guestCommands.RemoveDir(dir)}
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) executeChef(ui packersdk.Ui, comm packersdk.Communicator, config string, json string) error {
|
2015-05-27 17:41:47 -04:00
|
|
|
p.config.ctx.Data = &ExecuteTemplate{
|
2014-01-24 20:06:55 -05:00
|
|
|
ConfigPath: config,
|
|
|
|
JsonPath: json,
|
|
|
|
Sudo: !p.config.PreventSudo,
|
2015-05-27 17:41:47 -04:00
|
|
|
}
|
2019-04-03 11:14:55 -04:00
|
|
|
ctx := context.TODO()
|
|
|
|
|
2015-05-27 17:41:47 -04:00
|
|
|
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-13 05:25:12 -05:00
|
|
|
if p.config.ElevatedUser != "" {
|
2020-11-09 06:16:44 -05:00
|
|
|
command, err = guestexec.GenerateElevatedRunner(command, p)
|
2018-12-13 05:25:12 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message(fmt.Sprintf("Executing Chef: %s", command))
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd := &packersdk.RemoteCmd{
|
2014-01-24 20:06:55 -05:00
|
|
|
Command: command,
|
|
|
|
}
|
|
|
|
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-03 11:14:55 -04:00
|
|
|
if cmd.ExitStatus() != 0 {
|
|
|
|
return fmt.Errorf("Non-zero exit status: %d", cmd.ExitStatus())
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) installChef(ui packersdk.Ui, comm packersdk.Communicator, version string) error {
|
2014-01-24 20:06:55 -05:00
|
|
|
ui.Message("Installing Chef...")
|
2019-04-03 11:14:55 -04:00
|
|
|
ctx := context.TODO()
|
2014-01-24 20:06:55 -05:00
|
|
|
|
2015-05-27 17:41:47 -04:00
|
|
|
p.config.ctx.Data = &InstallChefTemplate{
|
2019-12-09 14:17:04 -05:00
|
|
|
Sudo: !p.config.PreventSudo,
|
|
|
|
Version: version,
|
2015-05-27 17:41:47 -04:00
|
|
|
}
|
|
|
|
command, err := interpolate.Render(p.config.InstallCommand, &p.config.ctx)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-08-20 16:27:51 -04:00
|
|
|
ui.Message(command)
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
cmd := &packersdk.RemoteCmd{Command: command}
|
2019-04-03 11:14:55 -04:00
|
|
|
if err := cmd.RunWithUi(ctx, comm, ui); err != nil {
|
2014-01-24 20:06:55 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-03 11:14:55 -04:00
|
|
|
if cmd.ExitStatus() != 0 {
|
2014-01-24 20:06:55 -05:00
|
|
|
return fmt.Errorf(
|
2019-04-03 11:14:55 -04:00
|
|
|
"Install script exited with non-zero exit status %d", cmd.ExitStatus())
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-01 11:48:04 -04:00
|
|
|
func (p *Provisioner) deepJsonFix(key string, current interface{}) (interface{}, error) {
|
|
|
|
if current == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch c := current.(type) {
|
|
|
|
case []interface{}:
|
|
|
|
val := make([]interface{}, len(c))
|
|
|
|
for i, v := range c {
|
|
|
|
var err error
|
|
|
|
val[i], err = p.deepJsonFix(fmt.Sprintf("%s[%d]", key, i), v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val, nil
|
|
|
|
case []uint8:
|
|
|
|
return string(c), nil
|
|
|
|
case map[interface{}]interface{}:
|
|
|
|
val := make(map[string]interface{})
|
|
|
|
for k, v := range c {
|
|
|
|
ks, ok := k.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("%s: key is not string", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
val[ks], err = p.deepJsonFix(
|
|
|
|
fmt.Sprintf("%s.%s", key, ks), v)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val, nil
|
|
|
|
default:
|
|
|
|
return current, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
func (p *Provisioner) processJsonUserVars() (map[string]interface{}, error) {
|
|
|
|
jsonBytes, err := json.Marshal(p.config.Json)
|
|
|
|
if err != nil {
|
|
|
|
// This really shouldn't happen since we literally just unmarshalled
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the user variables so that we can restore them later, and
|
|
|
|
// make sure we make the quotes JSON-friendly in the user variables.
|
|
|
|
originalUserVars := make(map[string]string)
|
2015-05-27 17:41:47 -04:00
|
|
|
for k, v := range p.config.ctx.UserVariables {
|
2014-01-24 20:06:55 -05:00
|
|
|
originalUserVars[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we reset them no matter what
|
|
|
|
defer func() {
|
2015-05-27 17:41:47 -04:00
|
|
|
p.config.ctx.UserVariables = originalUserVars
|
2014-01-24 20:06:55 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Make the current user variables JSON string safe.
|
2015-05-27 17:41:47 -04:00
|
|
|
for k, v := range p.config.ctx.UserVariables {
|
2014-01-24 20:06:55 -05:00
|
|
|
v = strings.Replace(v, `\`, `\\`, -1)
|
|
|
|
v = strings.Replace(v, `"`, `\"`, -1)
|
2015-05-27 17:41:47 -04:00
|
|
|
p.config.ctx.UserVariables[k] = v
|
2014-01-24 20:06:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process the bytes with the template processor
|
2015-05-27 17:41:47 -04:00
|
|
|
p.config.ctx.Data = nil
|
|
|
|
jsonBytesProcessed, err := interpolate.Render(string(jsonBytes), &p.config.ctx)
|
2014-01-24 20:06:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var result map[string]interface{}
|
|
|
|
if err := json.Unmarshal([]byte(jsonBytesProcessed), &result); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2020-11-19 18:10:00 -05:00
|
|
|
func (p *Provisioner) Communicator() packersdk.Communicator {
|
2018-12-13 05:25:12 -05:00
|
|
|
return p.communicator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provisioner) ElevatedUser() string {
|
|
|
|
return p.config.ElevatedUser
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provisioner) ElevatedPassword() string {
|
|
|
|
// Replace ElevatedPassword for winrm users who used this feature
|
2019-12-12 19:42:53 -05:00
|
|
|
p.config.ctx.Data = p.generatedData
|
2018-12-13 05:25:12 -05:00
|
|
|
|
|
|
|
elevatedPassword, _ := interpolate.Render(p.config.ElevatedPassword, &p.config.ctx)
|
|
|
|
|
|
|
|
return elevatedPassword
|
|
|
|
}
|
|
|
|
|
2014-01-24 20:06:55 -05:00
|
|
|
var DefaultConfigTemplate = `
|
|
|
|
log_level :info
|
|
|
|
log_location STDOUT
|
|
|
|
chef_server_url "{{.ServerUrl}}"
|
2015-04-09 02:15:16 -04:00
|
|
|
client_key "{{.ClientKey}}"
|
2019-05-17 11:19:22 -04:00
|
|
|
chef_license "{{.ChefLicense}}"
|
2015-08-20 16:27:51 -04:00
|
|
|
{{if ne .EncryptedDataBagSecretPath ""}}
|
2015-08-21 18:06:24 -04:00
|
|
|
encrypted_data_bag_secret "{{.EncryptedDataBagSecretPath}}"
|
|
|
|
{{end}}
|
2014-04-24 03:09:30 -04:00
|
|
|
{{if ne .ValidationClientName ""}}
|
|
|
|
validation_client_name "{{.ValidationClientName}}"
|
|
|
|
{{else}}
|
2014-01-24 20:06:55 -05:00
|
|
|
validation_client_name "chef-validator"
|
2014-04-24 03:09:30 -04:00
|
|
|
{{end}}
|
2014-02-24 12:45:04 -05:00
|
|
|
{{if ne .ValidationKeyPath ""}}
|
|
|
|
validation_key "{{.ValidationKeyPath}}"
|
|
|
|
{{end}}
|
2014-01-24 20:06:55 -05:00
|
|
|
node_name "{{.NodeName}}"
|
2014-05-21 09:24:34 -04:00
|
|
|
{{if ne .ChefEnvironment ""}}
|
|
|
|
environment "{{.ChefEnvironment}}"
|
|
|
|
{{end}}
|
2018-01-31 11:49:04 -05:00
|
|
|
{{if ne .PolicyGroup ""}}
|
|
|
|
policy_group "{{.PolicyGroup}}"
|
|
|
|
{{end}}
|
|
|
|
{{if ne .PolicyName ""}}
|
|
|
|
policy_name "{{.PolicyName}}"
|
|
|
|
{{end}}
|
2014-12-05 12:26:41 -05:00
|
|
|
{{if ne .SslVerifyMode ""}}
|
|
|
|
ssl_verify_mode :{{.SslVerifyMode}}
|
|
|
|
{{end}}
|
2018-01-12 17:53:49 -05:00
|
|
|
{{if ne .TrustedCertsDir ""}}
|
|
|
|
trusted_certs_dir "{{.TrustedCertsDir}}"
|
|
|
|
{{end}}
|
2014-01-24 20:06:55 -05:00
|
|
|
`
|
2015-06-24 07:46:59 -04:00
|
|
|
|
|
|
|
var DefaultKnifeTemplate = `
|
|
|
|
log_level :info
|
|
|
|
log_location STDOUT
|
|
|
|
chef_server_url "{{.ServerUrl}}"
|
|
|
|
client_key "{{.ClientKey}}"
|
|
|
|
node_name "{{.NodeName}}"
|
|
|
|
{{if ne .SslVerifyMode ""}}
|
|
|
|
ssl_verify_mode :{{.SslVerifyMode}}
|
|
|
|
{{end}}
|
2018-01-12 17:53:49 -05:00
|
|
|
{{if ne .TrustedCertsDir ""}}
|
|
|
|
trusted_certs_dir "{{.TrustedCertsDir}}"
|
|
|
|
{{end}}
|
2015-06-24 07:46:59 -04:00
|
|
|
`
|