Updates the chef provisioner to allow specifying a channel (#17355)
* Updates the chef provisioner to allow specifying a channel This also updates the omnitruck url to the current url. Signed-off-by: Scott Hain <shain@chef.io> * Update omnitruck URL Signed-off-by: Scott Hain <shain@chef.io>
This commit is contained in:
parent
6b6b92f6b3
commit
07aeea51da
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
chmod = "find %s -maxdepth 1 -type f -exec /bin/chmod %d {} +"
|
chmod = "find %s -maxdepth 1 -type f -exec /bin/chmod %d {} +"
|
||||||
installURL = "https://www.chef.io/chef/install.sh"
|
installURL = "https://omnitruck.chef.io/install.sh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *provisioner) linuxInstallChefClient(o terraform.UIOutput, comm communicator.Communicator) error {
|
func (p *provisioner) linuxInstallChefClient(o terraform.UIOutput, comm communicator.Communicator) error {
|
||||||
|
@ -34,7 +34,7 @@ func (p *provisioner) linuxInstallChefClient(o terraform.UIOutput, comm communic
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then execute the install.sh scrip to download and install Chef Client
|
// 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))
|
err = p.runCommand(o, comm, fmt.Sprintf("%sbash ./install.sh -v %q -c %s", prefix, p.Version, p.Channel))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"sudo curl -LO https://www.chef.io/chef/install.sh": true,
|
"sudo curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"sudo bash ./install.sh -v \"\"": true,
|
"sudo bash ./install.sh -v \"\" -c stable": true,
|
||||||
"sudo rm -f install.sh": true,
|
"sudo rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"curl -LO https://www.chef.io/chef/install.sh": true,
|
"curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"bash ./install.sh -v \"\"": true,
|
"bash ./install.sh -v \"\" -c stable": true,
|
||||||
"rm -f install.sh": true,
|
"rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"http_proxy='http://proxy.local' curl -LO https://www.chef.io/chef/install.sh": true,
|
"http_proxy='http://proxy.local' curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"http_proxy='http://proxy.local' bash ./install.sh -v \"\"": true,
|
"http_proxy='http://proxy.local' bash ./install.sh -v \"\" -c stable": true,
|
||||||
"http_proxy='http://proxy.local' rm -f install.sh": true,
|
"http_proxy='http://proxy.local' rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -79,9 +79,9 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"https_proxy='https://proxy.local' curl -LO https://www.chef.io/chef/install.sh": true,
|
"https_proxy='https://proxy.local' curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"https_proxy='https://proxy.local' bash ./install.sh -v \"\"": true,
|
"https_proxy='https://proxy.local' bash ./install.sh -v \"\" -c stable": true,
|
||||||
"https_proxy='https://proxy.local' rm -f install.sh": true,
|
"https_proxy='https://proxy.local' rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
||||||
"curl -LO https://www.chef.io/chef/install.sh": true,
|
"curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
||||||
"bash ./install.sh -v \"\"": true,
|
"bash ./install.sh -v \"\" -c stable": true,
|
||||||
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
"http_proxy='http://proxy.local' no_proxy='http://local.local,http://local.org' " +
|
||||||
"rm -f install.sh": true,
|
"rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
|
@ -119,9 +119,28 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: map[string]bool{
|
Commands: map[string]bool{
|
||||||
"curl -LO https://www.chef.io/chef/install.sh": true,
|
"curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
"bash ./install.sh -v \"11.18.6\"": true,
|
"bash ./install.sh -v \"11.18.6\" -c stable": true,
|
||||||
"rm -f install.sh": true,
|
"rm -f install.sh": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
"Channel": {
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"channel": "current",
|
||||||
|
"node_name": "nodename1",
|
||||||
|
"prevent_sudo": true,
|
||||||
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
|
"server_url": "https://chef.local",
|
||||||
|
"user_name": "bob",
|
||||||
|
"user_key": "USER-KEY",
|
||||||
|
"version": "11.18.6",
|
||||||
|
},
|
||||||
|
|
||||||
|
Commands: map[string]bool{
|
||||||
|
"curl -LO https://omnitruck.chef.io/install.sh": true,
|
||||||
|
"bash ./install.sh -v \"11.18.6\" -c current": true,
|
||||||
|
"rm -f install.sh": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ type provisionFn func(terraform.UIOutput, communicator.Communicator) error
|
||||||
|
|
||||||
type provisioner struct {
|
type provisioner struct {
|
||||||
Attributes map[string]interface{}
|
Attributes map[string]interface{}
|
||||||
|
Channel string
|
||||||
ClientOptions []string
|
ClientOptions []string
|
||||||
DisableReporting bool
|
DisableReporting bool
|
||||||
Environment string
|
Environment string
|
||||||
|
@ -149,6 +150,11 @@ func Provisioner() terraform.ResourceProvisioner {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
},
|
},
|
||||||
|
"channel": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Default: "stable",
|
||||||
|
},
|
||||||
"client_options": &schema.Schema{
|
"client_options": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
@ -725,6 +731,7 @@ func (p *provisioner) copyOutput(o terraform.UIOutput, r io.Reader, doneCh chan<
|
||||||
|
|
||||||
func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
|
func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
|
||||||
p := &provisioner{
|
p := &provisioner{
|
||||||
|
Channel: d.Get("channel").(string),
|
||||||
ClientOptions: getStringList(d.Get("client_options")),
|
ClientOptions: getStringList(d.Get("client_options")),
|
||||||
DisableReporting: d.Get("disable_reporting").(bool),
|
DisableReporting: d.Get("disable_reporting").(bool),
|
||||||
Environment: d.Get("environment").(string),
|
Environment: d.Get("environment").(string),
|
||||||
|
|
|
@ -23,7 +23,7 @@ switch ($winver)
|
||||||
|
|
||||||
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
||||||
|
|
||||||
$url = "http://www.chef.io/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v=%s"
|
$url = "http://omnitruck.chef.io/%s/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v=%s"
|
||||||
$dest = [System.IO.Path]::GetTempFileName()
|
$dest = [System.IO.Path]::GetTempFileName()
|
||||||
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
||||||
$downloader = New-Object System.Net.WebClient
|
$downloader = New-Object System.Net.WebClient
|
||||||
|
@ -48,7 +48,7 @@ Start-Process -FilePath msiexec -ArgumentList /qn, /i, $dest -Wait
|
||||||
|
|
||||||
func (p *provisioner) windowsInstallChefClient(o terraform.UIOutput, comm communicator.Communicator) error {
|
func (p *provisioner) windowsInstallChefClient(o terraform.UIOutput, comm communicator.Communicator) error {
|
||||||
script := path.Join(path.Dir(comm.ScriptPath()), "ChefClient.ps1")
|
script := path.Join(path.Dir(comm.ScriptPath()), "ChefClient.ps1")
|
||||||
content := fmt.Sprintf(installScript, p.Version, p.HTTPProxy, strings.Join(p.NOProxy, ","))
|
content := fmt.Sprintf(installScript, p.Channel, p.Version, p.HTTPProxy, strings.Join(p.NOProxy, ","))
|
||||||
|
|
||||||
// Copy the script to the new instance
|
// Copy the script to the new instance
|
||||||
if err := comm.UploadScript(script, strings.NewReader(content)); err != nil {
|
if err := comm.UploadScript(script, strings.NewReader(content)); err != nil {
|
||||||
|
|
|
@ -72,6 +72,26 @@ func TestResourceProvider_windowsInstallChefClient(t *testing.T) {
|
||||||
"ChefClient.ps1": versionWindowsInstallScript,
|
"ChefClient.ps1": versionWindowsInstallScript,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"Channel": {
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"channel": "current",
|
||||||
|
"node_name": "nodename1",
|
||||||
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
|
"server_url": "https://chef.local",
|
||||||
|
"user_name": "bob",
|
||||||
|
"user_key": "USER-KEY",
|
||||||
|
"version": "11.18.6",
|
||||||
|
},
|
||||||
|
|
||||||
|
Commands: map[string]bool{
|
||||||
|
"powershell -NoProfile -ExecutionPolicy Bypass -File ChefClient.ps1": true,
|
||||||
|
},
|
||||||
|
|
||||||
|
UploadScripts: map[string]string{
|
||||||
|
"ChefClient.ps1": channelWindowsInstallScript,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
o := new(terraform.MockUIOutput)
|
o := new(terraform.MockUIOutput)
|
||||||
|
@ -219,7 +239,7 @@ switch ($winver)
|
||||||
|
|
||||||
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
||||||
|
|
||||||
$url = "http://www.chef.io/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v="
|
$url = "http://omnitruck.chef.io/stable/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v="
|
||||||
$dest = [System.IO.Path]::GetTempFileName()
|
$dest = [System.IO.Path]::GetTempFileName()
|
||||||
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
||||||
$downloader = New-Object System.Net.WebClient
|
$downloader = New-Object System.Net.WebClient
|
||||||
|
@ -256,7 +276,7 @@ switch ($winver)
|
||||||
|
|
||||||
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
||||||
|
|
||||||
$url = "http://www.chef.io/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v="
|
$url = "http://omnitruck.chef.io/stable/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v="
|
||||||
$dest = [System.IO.Path]::GetTempFileName()
|
$dest = [System.IO.Path]::GetTempFileName()
|
||||||
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
||||||
$downloader = New-Object System.Net.WebClient
|
$downloader = New-Object System.Net.WebClient
|
||||||
|
@ -293,7 +313,43 @@ switch ($winver)
|
||||||
|
|
||||||
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
||||||
|
|
||||||
$url = "http://www.chef.io/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v=11.18.6"
|
$url = "http://omnitruck.chef.io/stable/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v=11.18.6"
|
||||||
|
$dest = [System.IO.Path]::GetTempFileName()
|
||||||
|
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
||||||
|
$downloader = New-Object System.Net.WebClient
|
||||||
|
|
||||||
|
$http_proxy = ''
|
||||||
|
if ($http_proxy -ne '') {
|
||||||
|
$no_proxy = ''
|
||||||
|
if ($no_proxy -eq ''){
|
||||||
|
$no_proxy = "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
$proxy = New-Object System.Net.WebProxy($http_proxy, $true, ,$no_proxy.Split(','))
|
||||||
|
$downloader.proxy = $proxy
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host 'Downloading Chef Client...'
|
||||||
|
$downloader.DownloadFile($url, $dest)
|
||||||
|
|
||||||
|
Write-Host 'Installing Chef Client...'
|
||||||
|
Start-Process -FilePath msiexec -ArgumentList /qn, /i, $dest -Wait
|
||||||
|
`
|
||||||
|
const channelWindowsInstallScript = `
|
||||||
|
$winver = [System.Environment]::OSVersion.Version | % {"{0}.{1}" -f $_.Major,$_.Minor}
|
||||||
|
|
||||||
|
switch ($winver)
|
||||||
|
{
|
||||||
|
"6.0" {$machine_os = "2008"}
|
||||||
|
"6.1" {$machine_os = "2008r2"}
|
||||||
|
"6.2" {$machine_os = "2012"}
|
||||||
|
"6.3" {$machine_os = "2012"}
|
||||||
|
default {$machine_os = "2008r2"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([System.IntPtr]::Size -eq 4) {$machine_arch = "i686"} else {$machine_arch = "x86_64"}
|
||||||
|
|
||||||
|
$url = "http://omnitruck.chef.io/current/chef/download?p=windows&pv=$machine_os&m=$machine_arch&v=11.18.6"
|
||||||
$dest = [System.IO.Path]::GetTempFileName()
|
$dest = [System.IO.Path]::GetTempFileName()
|
||||||
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
$dest = [System.IO.Path]::ChangeExtension($dest, ".msi")
|
||||||
$downloader = New-Object System.Net.WebClient
|
$downloader = New-Object System.Net.WebClient
|
||||||
|
|
Loading…
Reference in New Issue