github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/provisioners/chef/linux_provisioner.go (about)

     1  package chef
     2  
     3  import (
     4  	"fmt"
     5  	"path"
     6  	"strings"
     7  
     8  	"github.com/hashicorp/terraform/communicator"
     9  	"github.com/hashicorp/terraform/terraform"
    10  )
    11  
    12  const (
    13  	installURL = "https://www.chef.io/chef/install.sh"
    14  )
    15  
    16  func (p *Provisioner) linuxInstallChefClient(
    17  	o terraform.UIOutput,
    18  	comm communicator.Communicator) error {
    19  
    20  	// Build up the command prefix
    21  	prefix := ""
    22  	if p.HTTPProxy != "" {
    23  		prefix += fmt.Sprintf("http_proxy='%s' ", p.HTTPProxy)
    24  	}
    25  	if p.HTTPSProxy != "" {
    26  		prefix += fmt.Sprintf("https_proxy='%s' ", p.HTTPSProxy)
    27  	}
    28  	if p.NOProxy != nil {
    29  		prefix += fmt.Sprintf("no_proxy='%s' ", strings.Join(p.NOProxy, ","))
    30  	}
    31  
    32  	// First download the install.sh script from Chef
    33  	err := p.runCommand(o, comm, fmt.Sprintf("%scurl -LO %s", prefix, installURL))
    34  	if err != nil {
    35  		return err
    36  	}
    37  
    38  	// Then execute the install.sh scrip to download and install Chef Client
    39  	err = p.runCommand(o, comm, fmt.Sprintf("%sbash ./install.sh -v %q", prefix, p.Version))
    40  	if err != nil {
    41  		return err
    42  	}
    43  
    44  	// And finally cleanup the install.sh script again
    45  	return p.runCommand(o, comm, fmt.Sprintf("%srm -f install.sh", prefix))
    46  }
    47  
    48  func (p *Provisioner) linuxCreateConfigFiles(
    49  	o terraform.UIOutput,
    50  	comm communicator.Communicator) error {
    51  	// Make sure the config directory exists
    52  	if err := p.runCommand(o, comm, "mkdir -p "+linuxConfDir); err != nil {
    53  		return err
    54  	}
    55  
    56  	// Make sure we have enough rights to upload the files if using sudo
    57  	if p.useSudo {
    58  		if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
    59  			return err
    60  		}
    61  	}
    62  
    63  	if err := p.deployConfigFiles(o, comm, linuxConfDir); err != nil {
    64  		return err
    65  	}
    66  
    67  	if len(p.OhaiHints) > 0 {
    68  		// Make sure the hits directory exists
    69  		hintsDir := path.Join(linuxConfDir, "ohai/hints")
    70  		if err := p.runCommand(o, comm, "mkdir -p "+hintsDir); err != nil {
    71  			return err
    72  		}
    73  
    74  		// Make sure we have enough rights to upload the hints if using sudo
    75  		if p.useSudo {
    76  			if err := p.runCommand(o, comm, "chmod 777 "+hintsDir); err != nil {
    77  				return err
    78  			}
    79  		}
    80  
    81  		if err := p.deployOhaiHints(o, comm, hintsDir); err != nil {
    82  			return err
    83  		}
    84  
    85  		// When done copying the hints restore the rights and make sure root is owner
    86  		if p.useSudo {
    87  			if err := p.runCommand(o, comm, "chmod 755 "+hintsDir); err != nil {
    88  				return err
    89  			}
    90  			if err := p.runCommand(o, comm, "chown -R root.root "+hintsDir); err != nil {
    91  				return err
    92  			}
    93  		}
    94  	}
    95  
    96  	// When done copying all files restore the rights and make sure root is owner
    97  	if p.useSudo {
    98  		if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
    99  			return err
   100  		}
   101  		if err := p.runCommand(o, comm, "chown -R root.root "+linuxConfDir); err != nil {
   102  			return err
   103  		}
   104  	}
   105  
   106  	return nil
   107  }