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-06-25 15:48:54 +02:00
|
|
|
"path"
|
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-06-25 14:29:48 +02:00
|
|
|
func (p *Provisioner) linuxInstallChefClient(
|
2015-05-08 13:45:31 +02:00
|
|
|
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
|
2015-06-30 14:03:06 +02:00
|
|
|
err = p.runCommand(o, comm, fmt.Sprintf("%sbash ./install.sh -v %q", prefix, p.Version))
|
2015-05-08 23:25:24 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-06-25 14:29:48 +02:00
|
|
|
func (p *Provisioner) linuxCreateConfigFiles(
|
2015-05-08 13:45:31 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-06-25 15:48:54 +02:00
|
|
|
if len(p.OhaiHints) > 0 {
|
|
|
|
// Make sure the hits directory exists
|
|
|
|
hintsDir := path.Join(linuxConfDir, "ohai/hints")
|
|
|
|
if err := p.runCommand(o, comm, "mkdir -p "+hintsDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := p.deployOhaiHints(o, comm, hintsDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-08 13:45:31 +02:00
|
|
|
// 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
|
|
|
|
}
|