terraform/builtin/provisioners/chef-client/ssh_provisioner.go

73 lines
1.8 KiB
Go
Raw Normal View History

package chefclient
import (
"bytes"
"strings"
"github.com/hashicorp/terraform/communicator"
"github.com/hashicorp/terraform/terraform"
)
func (p *Provisioner) sshInstallChefClient(
o terraform.UIOutput,
comm communicator.Communicator) error {
var installCmd bytes.Buffer
// Build up a single command based on the given config options
installCmd.WriteString("curl")
if p.HTTPProxy != "" {
installCmd.WriteString(" --proxy " + p.HTTPProxy)
}
if p.NOProxy != nil {
installCmd.WriteString(" --noproxy " + strings.Join(p.NOProxy, ","))
}
installCmd.WriteString(" -LO https://www.chef.io/chef/install.sh 2>/dev/null &&")
if !p.PreventSudo {
installCmd.WriteString(" sudo")
}
installCmd.WriteString(" bash ./install.sh")
if p.Version != "" {
installCmd.WriteString(" -v " + p.Version)
}
2015-05-08 18:17:57 +02:00
installCmd.WriteString(" &&")
if !p.PreventSudo {
installCmd.WriteString(" sudo")
}
installCmd.WriteString(" rm -f install.sh")
// Execute the command to install Chef Client
return p.runCommand(o, comm, installCmd.String())
}
func (p *Provisioner) sshCreateConfigFiles(
o terraform.UIOutput,
comm communicator.Communicator) error {
// Make sure the config directory exists
2015-05-08 18:17:57 +02:00
if err := p.runCommand(o, comm, "mkdir -p "+linuxConfDir); err != nil {
return err
}
// Make sure we have enough rights to upload the files if using sudo
if !p.PreventSudo {
if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
return err
}
}
if err := p.deployConfigFiles(o, comm, linuxConfDir); err != nil {
return err
}
// When done copying the files restore the rights and make sure root is owner
if !p.PreventSudo {
if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
return err
}
if err := p.runCommand(o, comm, "chown -R root.root "+linuxConfDir); err != nil {
return err
}
}
return nil
}