2015-05-08 23:25:24 +02:00
|
|
|
package chef
|
2015-05-08 13:45:31 +02:00
|
|
|
|
|
|
|
import (
|
2015-05-08 23:25:24 +02:00
|
|
|
"fmt"
|
2015-05-08 13:45:31 +02:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/communicator"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2015-05-08 23:25:24 +02:00
|
|
|
const (
|
|
|
|
installURL = "https://www.chef.io/chef/install.sh"
|
|
|
|
)
|
|
|
|
|
2015-05-08 13:45:31 +02:00
|
|
|
func (p *Provisioner) sshInstallChefClient(
|
|
|
|
o terraform.UIOutput,
|
|
|
|
comm communicator.Communicator) error {
|
|
|
|
|
2015-05-08 23:25:24 +02:00
|
|
|
// Build up the command prefix
|
|
|
|
prefix := ""
|
2015-05-08 13:45:31 +02:00
|
|
|
if p.HTTPProxy != "" {
|
2015-05-08 23:25:24 +02:00
|
|
|
prefix += fmt.Sprintf("proxy_http='%s' ", p.HTTPProxy)
|
2015-05-08 13:45:31 +02:00
|
|
|
}
|
|
|
|
if p.NOProxy != nil {
|
2015-05-08 23:25:24 +02:00
|
|
|
prefix += fmt.Sprintf("no_proxy='%s' ", strings.Join(p.NOProxy, ","))
|
2015-05-08 13:45:31 +02:00
|
|
|
}
|
2015-05-08 23:25:24 +02:00
|
|
|
|
|
|
|
// First download the install.sh script from Chef
|
|
|
|
err := p.runCommand(o, comm, fmt.Sprintf("%scurl -LO %s", prefix, installURL))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-05-08 13:45:31 +02:00
|
|
|
}
|
2015-05-08 23:25:24 +02:00
|
|
|
|
|
|
|
// Then execute the install.sh scrip to download and install Chef Client
|
|
|
|
err = p.runCommand(o, comm, fmt.Sprintf("%sbash ./install.sh -v %s", prefix, p.Version))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2015-05-08 18:17:57 +02:00
|
|
|
}
|
2015-05-08 13:45:31 +02:00
|
|
|
|
2015-05-08 23:25:24 +02:00
|
|
|
// And finally cleanup the install.sh script again
|
|
|
|
return p.runCommand(o, comm, fmt.Sprintf("%srm -f install.sh", prefix))
|
2015-05-08 13:45:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2015-05-08 13:45:31 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we have enough rights to upload the files if using sudo
|
2015-05-12 10:37:38 +02:00
|
|
|
if p.useSudo {
|
2015-05-08 13:45:31 +02:00
|
|
|
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
|
2015-05-12 10:37:38 +02:00
|
|
|
if p.useSudo {
|
2015-05-08 13:45:31 +02:00
|
|
|
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
|
|
|
|
}
|