github.com/bendemaree/terraform@v0.5.4-0.20150613200311-f50d97d6eee6/builtin/provisioners/chef/ssh_provisioner.go (about)

     1  package chef
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/hashicorp/terraform/communicator"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  const (
    12  	installURL = "https://www.chef.io/chef/install.sh"
    13  )
    14  
    15  func (p *Provisioner) sshInstallChefClient(
    16  	o terraform.UIOutput,
    17  	comm communicator.Communicator) error {
    18  
    19  	// Build up the command prefix
    20  	prefix := ""
    21  	if p.HTTPProxy != "" {
    22  		prefix += fmt.Sprintf("proxy_http='%s' ", p.HTTPProxy)
    23  	}
    24  	if p.NOProxy != nil {
    25  		prefix += fmt.Sprintf("no_proxy='%s' ", strings.Join(p.NOProxy, ","))
    26  	}
    27  
    28  	// First download the install.sh script from Chef
    29  	err := p.runCommand(o, comm, fmt.Sprintf("%scurl -LO %s", prefix, installURL))
    30  	if err != nil {
    31  		return err
    32  	}
    33  
    34  	// Then execute the install.sh scrip to download and install Chef Client
    35  	err = p.runCommand(o, comm, fmt.Sprintf("%sbash ./install.sh -v %s", prefix, p.Version))
    36  	if err != nil {
    37  		return err
    38  	}
    39  
    40  	// And finally cleanup the install.sh script again
    41  	return p.runCommand(o, comm, fmt.Sprintf("%srm -f install.sh", prefix))
    42  }
    43  
    44  func (p *Provisioner) sshCreateConfigFiles(
    45  	o terraform.UIOutput,
    46  	comm communicator.Communicator) error {
    47  	// Make sure the config directory exists
    48  	if err := p.runCommand(o, comm, "mkdir -p "+linuxConfDir); err != nil {
    49  		return err
    50  	}
    51  
    52  	// Make sure we have enough rights to upload the files if using sudo
    53  	if p.useSudo {
    54  		if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
    55  			return err
    56  		}
    57  	}
    58  
    59  	if err := p.deployConfigFiles(o, comm, linuxConfDir); err != nil {
    60  		return err
    61  	}
    62  
    63  	// When done copying the files restore the rights and make sure root is owner
    64  	if p.useSudo {
    65  		if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
    66  			return err
    67  		}
    68  		if err := p.runCommand(o, comm, "chown -R root.root "+linuxConfDir); err != nil {
    69  			return err
    70  		}
    71  	}
    72  
    73  	return nil
    74  }