Common provisioner helpers (#10229)
* update docstrings to make it clear that plugins are servers and core is client * move provisioner guest helper functions into common dir.
This commit is contained in:
parent
b7568f5a4d
commit
cd74456026
|
@ -1,4 +1,4 @@
|
||||||
package provisioner
|
package guestexec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
|
@ -1,4 +1,4 @@
|
||||||
package provisioner
|
package guestexec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
|
@ -1,4 +1,4 @@
|
||||||
package provisioner
|
package guestexec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package provisioner
|
package guestexec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -10,8 +10,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client is the client end that communicates with a Packer RPC server.
|
// Client is the client end that communicates with a Packer RPC server.
|
||||||
// Establishing a connection is up to the user, the Client can just
|
// Establishing a connection is up to the user. The Client can communicate over
|
||||||
// communicate over any ReadWriteCloser.
|
// any ReadWriteCloser. In Packer, each "plugin" (builder, provisioner,
|
||||||
|
// and post-processor) creates and launches a server. The the packer "core"
|
||||||
|
// creates and uses the client.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
mux *muxBroker
|
mux *muxBroker
|
||||||
client *rpc.Client
|
client *rpc.Client
|
||||||
|
|
|
@ -23,7 +23,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server represents an RPC server for Packer. This must be paired on
|
// Server represents an RPC server for Packer. This must be paired on
|
||||||
// the other side with a Client.
|
// the other side with a Client. In Packer, each "plugin" (builder, provisioner,
|
||||||
|
// and post-processor) creates and launches a server. The client created and
|
||||||
|
// used by the packer "core"
|
||||||
type Server struct {
|
type Server struct {
|
||||||
mux *muxBroker
|
mux *muxBroker
|
||||||
streamId uint32
|
streamId uint32
|
||||||
|
|
|
@ -17,10 +17,10 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/common/uuid"
|
"github.com/hashicorp/packer/common/uuid"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,13 +32,13 @@ type guestOSTypeConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
guestexec.UnixOSType: {
|
||||||
executeCommand: "{{if .Sudo}}sudo {{end}}chef-client --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
executeCommand: "{{if .Sudo}}sudo {{end}}chef-client --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
||||||
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
||||||
knifeCommand: "{{if .Sudo}}sudo {{end}}knife {{.Args}} {{.Flags}}",
|
knifeCommand: "{{if .Sudo}}sudo {{end}}knife {{.Args}} {{.Flags}}",
|
||||||
stagingDir: "/tmp/packer-chef-client",
|
stagingDir: "/tmp/packer-chef-client",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
guestexec.WindowsOSType: {
|
||||||
executeCommand: "c:/opscode/chef/bin/chef-client.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
executeCommand: "c:/opscode/chef/bin/chef-client.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
||||||
installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
|
installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
|
||||||
knifeCommand: "c:/opscode/chef/bin/knife.bat {{.Args}} {{.Flags}}",
|
knifeCommand: "c:/opscode/chef/bin/knife.bat {{.Args}} {{.Flags}}",
|
||||||
|
@ -86,7 +86,7 @@ type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
communicator packer.Communicator
|
communicator packer.Communicator
|
||||||
guestOSTypeConfig guestOSTypeConfig
|
guestOSTypeConfig guestOSTypeConfig
|
||||||
guestCommands *provisioner.GuestCommands
|
guestCommands *guestexec.GuestCommands
|
||||||
generatedData map[string]interface{}
|
generatedData map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.GuestOSType == "" {
|
if p.config.GuestOSType == "" {
|
||||||
p.config.GuestOSType = provisioner.DefaultOSType
|
p.config.GuestOSType = guestexec.DefaultOSType
|
||||||
}
|
}
|
||||||
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guestCommands, err = provisioner.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,7 @@ func (p *Provisioner) executeChef(ui packer.Ui, comm packer.Communicator, config
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.ElevatedUser != "" {
|
if p.config.ElevatedUser != "" {
|
||||||
command, err = provisioner.GenerateElevatedRunner(command, p)
|
command, err = guestexec.GenerateElevatedRunner(command, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,12 +30,12 @@ type guestOSTypeConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
guestexec.UnixOSType: {
|
||||||
executeCommand: "{{if .Sudo}}sudo {{end}}chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
executeCommand: "{{if .Sudo}}sudo {{end}}chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
||||||
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
||||||
stagingDir: "/tmp/packer-chef-solo",
|
stagingDir: "/tmp/packer-chef-solo",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
guestexec.WindowsOSType: {
|
||||||
executeCommand: "c:/opscode/chef/bin/chef-solo.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
executeCommand: "c:/opscode/chef/bin/chef-solo.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
||||||
installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
|
installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
|
||||||
stagingDir: "C:/Windows/Temp/packer-chef-solo",
|
stagingDir: "C:/Windows/Temp/packer-chef-solo",
|
||||||
|
@ -70,7 +70,7 @@ type Config struct {
|
||||||
type Provisioner struct {
|
type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
guestOSTypeConfig guestOSTypeConfig
|
guestOSTypeConfig guestOSTypeConfig
|
||||||
guestCommands *provisioner.GuestCommands
|
guestCommands *guestexec.GuestCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigTemplate struct {
|
type ConfigTemplate struct {
|
||||||
|
@ -121,7 +121,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.GuestOSType == "" {
|
if p.config.GuestOSType == "" {
|
||||||
p.config.GuestOSType = provisioner.DefaultOSType
|
p.config.GuestOSType = guestexec.DefaultOSType
|
||||||
}
|
}
|
||||||
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guestCommands, err = provisioner.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,13 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/common/retry"
|
"github.com/hashicorp/packer/common/retry"
|
||||||
"github.com/hashicorp/packer/common/shell"
|
"github.com/hashicorp/packer/common/shell"
|
||||||
"github.com/hashicorp/packer/common/uuid"
|
"github.com/hashicorp/packer/common/uuid"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/packer/tmp"
|
"github.com/hashicorp/packer/packer/tmp"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -522,7 +522,7 @@ func (p *Provisioner) createCommandTextPrivileged() (command string, err error)
|
||||||
return "", fmt.Errorf("Error processing command: %s", err)
|
return "", fmt.Errorf("Error processing command: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
command, err = provisioner.GenerateElevatedRunner(command, p)
|
command, err = guestexec.GenerateElevatedRunner(command, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error generating elevated runner: %s", err)
|
return "", fmt.Errorf("Error generating elevated runner: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ type guestOSTypeConfig struct {
|
||||||
|
|
||||||
// FIXME assumes both Packer host and target are same OS
|
// FIXME assumes both Packer host and target are same OS
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
guestexec.UnixOSType: {
|
||||||
tempDir: "/tmp",
|
tempDir: "/tmp",
|
||||||
stagingDir: "/tmp/packer-puppet-masterless",
|
stagingDir: "/tmp/packer-puppet-masterless",
|
||||||
executeCommand: "cd {{.WorkingDir}} && " +
|
executeCommand: "cd {{.WorkingDir}} && " +
|
||||||
|
@ -106,7 +106,7 @@ var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
facterVarsJoiner: " ",
|
facterVarsJoiner: " ",
|
||||||
modulePathJoiner: ":",
|
modulePathJoiner: ":",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
guestexec.WindowsOSType: {
|
||||||
tempDir: filepath.ToSlash(os.Getenv("TEMP")),
|
tempDir: filepath.ToSlash(os.Getenv("TEMP")),
|
||||||
stagingDir: filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-masterless",
|
stagingDir: filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-masterless",
|
||||||
executeCommand: "cd {{.WorkingDir}} && " +
|
executeCommand: "cd {{.WorkingDir}} && " +
|
||||||
|
@ -129,7 +129,7 @@ type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
communicator packer.Communicator
|
communicator packer.Communicator
|
||||||
guestOSTypeConfig guestOSTypeConfig
|
guestOSTypeConfig guestOSTypeConfig
|
||||||
guestCommands *provisioner.GuestCommands
|
guestCommands *guestexec.GuestCommands
|
||||||
generatedData map[string]interface{}
|
generatedData map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
|
|
||||||
// Set some defaults
|
// Set some defaults
|
||||||
if p.config.GuestOSType == "" {
|
if p.config.GuestOSType == "" {
|
||||||
p.config.GuestOSType = provisioner.DefaultOSType
|
p.config.GuestOSType = guestexec.DefaultOSType
|
||||||
}
|
}
|
||||||
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guestCommands, err = provisioner.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.ElevatedUser != "" {
|
if p.config.ElevatedUser != "" {
|
||||||
command, err = provisioner.GenerateElevatedRunner(command, p)
|
command, err = guestexec.GenerateElevatedRunner(command, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ type guestOSTypeConfig struct {
|
||||||
|
|
||||||
// FIXME assumes both Packer host and target are same OS
|
// FIXME assumes both Packer host and target are same OS
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
guestexec.UnixOSType: {
|
||||||
tempDir: "/tmp",
|
tempDir: "/tmp",
|
||||||
stagingDir: "/tmp/packer-puppet-server",
|
stagingDir: "/tmp/packer-puppet-server",
|
||||||
executeCommand: "cd {{.WorkingDir}} && " +
|
executeCommand: "cd {{.WorkingDir}} && " +
|
||||||
|
@ -102,7 +102,7 @@ var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
facterVarsFmt: "FACTER_%s='%s'",
|
facterVarsFmt: "FACTER_%s='%s'",
|
||||||
facterVarsJoiner: " ",
|
facterVarsJoiner: " ",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
guestexec.WindowsOSType: {
|
||||||
tempDir: filepath.ToSlash(os.Getenv("TEMP")),
|
tempDir: filepath.ToSlash(os.Getenv("TEMP")),
|
||||||
stagingDir: filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-server",
|
stagingDir: filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-server",
|
||||||
executeCommand: "cd {{.WorkingDir}} && " +
|
executeCommand: "cd {{.WorkingDir}} && " +
|
||||||
|
@ -124,7 +124,7 @@ type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
communicator packer.Communicator
|
communicator packer.Communicator
|
||||||
guestOSTypeConfig guestOSTypeConfig
|
guestOSTypeConfig guestOSTypeConfig
|
||||||
guestCommands *provisioner.GuestCommands
|
guestCommands *guestexec.GuestCommands
|
||||||
generatedData map[string]interface{}
|
generatedData map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.GuestOSType == "" {
|
if p.config.GuestOSType == "" {
|
||||||
p.config.GuestOSType = provisioner.DefaultOSType
|
p.config.GuestOSType = guestexec.DefaultOSType
|
||||||
}
|
}
|
||||||
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guestCommands, err = provisioner.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.PreventSudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.ElevatedUser != "" {
|
if p.config.ElevatedUser != "" {
|
||||||
command, err = provisioner.GenerateElevatedRunner(command, p)
|
command, err = guestexec.GenerateElevatedRunner(command, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,9 @@ import (
|
||||||
"github.com/hashicorp/go-getter/v2"
|
"github.com/hashicorp/go-getter/v2"
|
||||||
"github.com/hashicorp/hcl/v2/hcldec"
|
"github.com/hashicorp/hcl/v2/hcldec"
|
||||||
"github.com/hashicorp/packer/common"
|
"github.com/hashicorp/packer/common"
|
||||||
|
"github.com/hashicorp/packer/common/guestexec"
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/provisioner"
|
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ type Config struct {
|
||||||
type Provisioner struct {
|
type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
guestOSTypeConfig guestOSTypeConfig
|
guestOSTypeConfig guestOSTypeConfig
|
||||||
guestCommands *provisioner.GuestCommands
|
guestCommands *guestexec.GuestCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
type guestOSTypeConfig struct {
|
type guestOSTypeConfig struct {
|
||||||
|
@ -96,7 +96,7 @@ type guestOSTypeConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
guestexec.UnixOSType: {
|
||||||
configDir: "/etc/salt",
|
configDir: "/etc/salt",
|
||||||
tempDir: "/tmp/salt",
|
tempDir: "/tmp/salt",
|
||||||
stateRoot: "/srv/salt",
|
stateRoot: "/srv/salt",
|
||||||
|
@ -104,7 +104,7 @@ var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
bootstrapFetchCmd: "curl -L https://bootstrap.saltstack.com -o /tmp/install_salt.sh || wget -O /tmp/install_salt.sh https://bootstrap.saltstack.com",
|
bootstrapFetchCmd: "curl -L https://bootstrap.saltstack.com -o /tmp/install_salt.sh || wget -O /tmp/install_salt.sh https://bootstrap.saltstack.com",
|
||||||
bootstrapRunCmd: "sh /tmp/install_salt.sh",
|
bootstrapRunCmd: "sh /tmp/install_salt.sh",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
guestexec.WindowsOSType: {
|
||||||
configDir: "C:/salt/conf",
|
configDir: "C:/salt/conf",
|
||||||
tempDir: "C:/Windows/Temp/salt/",
|
tempDir: "C:/Windows/Temp/salt/",
|
||||||
stateRoot: "C:/salt/state",
|
stateRoot: "C:/salt/state",
|
||||||
|
@ -130,7 +130,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.GuestOSType == "" {
|
if p.config.GuestOSType == "" {
|
||||||
p.config.GuestOSType = provisioner.DefaultOSType
|
p.config.GuestOSType = guestexec.DefaultOSType
|
||||||
} else {
|
} else {
|
||||||
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
p.config.GuestOSType = strings.ToLower(p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.guestCommands, err = provisioner.NewGuestCommands(p.config.GuestOSType, !p.config.DisableSudo)
|
p.guestCommands, err = guestexec.NewGuestCommands(p.config.GuestOSType, !p.config.DisableSudo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
return fmt.Errorf("Invalid guest_os_type: \"%s\"", p.config.GuestOSType)
|
||||||
}
|
}
|
||||||
|
@ -413,7 +413,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
|
||||||
|
|
||||||
// Prepends sudo to supplied command if config says to
|
// Prepends sudo to supplied command if config says to
|
||||||
func (p *Provisioner) sudo(cmd string) string {
|
func (p *Provisioner) sudo(cmd string) string {
|
||||||
if p.config.DisableSudo || (p.config.GuestOSType == provisioner.WindowsOSType) {
|
if p.config.DisableSudo || (p.config.GuestOSType == guestexec.WindowsOSType) {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue