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