Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
adaceb77
Commit
adaceb77
authored
Jul 12, 2013
by
James Van Dyke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove redundant code and clean up some string concatenation.
Clean up Say statements.
parent
6a1d1cfb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
provisioner/chef-solo/provisioner.go
provisioner/chef-solo/provisioner.go
+30
-18
No files found.
provisioner/chef-solo/provisioner.go
View file @
adaceb77
...
...
@@ -19,10 +19,12 @@ import (
"text/template"
)
const
RemoteStagingPath
=
"/tmp/provision/chef-solo"
const
RemoteFileCachePath
=
"/tmp/provision/chef-solo"
const
RemoteCookbookPath
=
"/tmp/provision/chef-solo/cookbooks"
const
DefaultCookbooksPath
=
"cookbooks"
const
(
RemoteStagingPath
=
"/tmp/provision/chef-solo"
RemoteFileCachePath
=
"/tmp/provision/chef-solo"
RemoteCookbookPath
=
"/tmp/provision/chef-solo/cookbooks"
DefaultCookbooksPath
=
"cookbooks"
)
var
Ui
packer
.
Ui
...
...
@@ -68,7 +70,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
if
p
.
config
.
CookbooksPaths
==
nil
{
p
.
config
.
CookbooksPaths
=
[]
string
{
DefaultCookbooksPath
}
}
if
p
.
config
.
Recipes
==
nil
{
...
...
@@ -99,9 +100,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
func
(
p
*
Provisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
error
{
cookbooksPaths
:=
make
([]
string
,
len
(
p
.
config
.
CookbooksPaths
))
copy
(
cookbooksPaths
,
p
.
config
.
CookbooksPaths
)
var
err
error
Ui
=
ui
...
...
@@ -128,7 +126,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
// Upload all cookbooks
for
_
,
path
:=
range
c
ookbooksPaths
{
for
_
,
path
:=
range
p
.
config
.
C
ookbooksPaths
{
ui
.
Say
(
fmt
.
Sprintf
(
"Copying cookbook path: %s"
,
path
))
err
=
UploadLocalDirectory
(
path
,
comm
)
if
err
!=
nil
{
...
...
@@ -149,6 +147,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return
fmt
.
Errorf
(
"Error running Chef Solo: %s"
,
err
)
}
return
fmt
.
Errorf
(
"SUCESS"
)
return
nil
}
...
...
@@ -208,7 +208,7 @@ func CreateRemoteDirectory(path string, comm packer.Communicator) (err error) {
}
func
CreateSoloRb
(
cookbooksPaths
[]
string
,
comm
packer
.
Communicator
)
(
str
string
,
err
error
)
{
Ui
.
Say
(
fmt
.
Sprintf
(
"Creating Chef configuration file..."
)
)
Ui
.
Say
(
"Creating Chef configuration file..."
)
remotePath
:=
RemoteStagingPath
+
"/solo.rb"
...
...
@@ -220,11 +220,24 @@ func CreateSoloRb(cookbooksPaths []string, comm packer.Communicator) (str string
// Write our contents to it
writer
:=
bufio
.
NewWriter
(
tf
)
// Messy, messy...
cbPathsCat
:=
"
\"
"
+
RemoteCookbookPath
+
"/"
+
strings
.
Join
(
cookbooksPaths
,
"
\"
,
\"
"
+
RemoteCookbookPath
+
"/"
)
+
"
\"
"
contents
:=
"file_cache_path
\"
"
+
RemoteFileCachePath
+
"
\"\n
cookbook_path ["
+
cbPathsCat
+
"]
\n
"
var
cookbooksPathsFull
=
make
([]
string
,
len
(
cookbooksPaths
))
for
i
,
path
:=
range
cookbooksPaths
{
cookbooksPathsFull
[
i
]
=
"
\"
"
+
RemoteCookbookPath
+
"/"
+
path
+
"
\"
"
}
var
contents
bytes
.
Buffer
var
soloRbText
=
`
file_cache_path "{{.FileCachePath}}"
cookbook_path [{{.CookbookPath}}]
`
if
_
,
err
:=
writer
.
WriteString
(
contents
);
err
!=
nil
{
t
:=
template
.
Must
(
template
.
New
(
"soloRb"
)
.
Parse
(
soloRbText
))
t
.
Execute
(
&
contents
,
map
[
string
]
string
{
"FileCachePath"
:
RemoteFileCachePath
,
"CookbookPath"
:
strings
.
Join
(
cookbooksPathsFull
,
","
),
})
if
_
,
err
:=
writer
.
WriteString
(
contents
.
String
());
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Error preparing solo.rb: %s"
,
err
)
}
...
...
@@ -245,12 +258,12 @@ func CreateSoloRb(cookbooksPaths []string, comm packer.Communicator) (str string
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Error uploading Chef Solo configuration file: %s"
,
err
)
}
//executeCommand("sudo cat " + remotePath, comm)
return
remotePath
,
nil
}
func
CreateAttributesJson
(
jsonAttrs
map
[
string
]
interface
{},
recipes
[]
string
,
comm
packer
.
Communicator
)
(
str
string
,
err
error
)
{
Ui
.
Say
(
fmt
.
Sprintf
(
"Creating and uploading Chef attributes file"
)
)
Ui
.
Say
(
"Creating and uploading Chef attributes file"
)
remotePath
:=
RemoteStagingPath
+
"/node.json"
var
formattedRecipes
[]
string
...
...
@@ -305,7 +318,7 @@ func CreateAttributesJson(jsonAttrs map[string]interface{}, recipes []string, co
}
func
InstallChefSolo
(
preventSudo
bool
,
comm
packer
.
Communicator
)
(
err
error
)
{
Ui
.
Say
(
fmt
.
Sprintf
(
"Installing Chef Solo"
)
)
Ui
.
Say
(
"Installing Chef Solo"
)
var
command
bytes
.
Buffer
t
:=
template
.
Must
(
template
.
New
(
"install-chef"
)
.
Parse
(
"curl -L https://www.opscode.com/chef/install.sh | {{if .sudo}}sudo {{end}}bash"
))
...
...
@@ -329,7 +342,6 @@ func executeCommand(command string, comm packer.Communicator) (err error) {
cmd
.
Stdout
=
stdout_w
cmd
.
Stderr
=
stderr_w
//Ui.Say(fmt.Sprintf("Executing command: %s", cmd.Command))
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
err
=
comm
.
Start
(
&
cmd
)
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment