I'm new to Chef/Packer so apologies if this is a novice question, basically I'm trying to get Packer to use my local machine to build the image and execute a shell script. Following is my packer-build.json
{
"builders": [
{
"type": "file",
"name": "example",
"target": "./test_artifact.txt",
"content": "example content"
}
],
"provisioners": [
{
"type": "chef-solo",
"cookbook_paths": ["/Users/bakthak/code/nc_deployment/chef-repo/cookbooks"],
"staging_directory": "/Users/bakthak",
"execute_command": "sh /Users/bakthak/check.sh"
}
]
}
Running build with this file produces the output
==> example: Provisioning with chef-solo
example: Installing Chef...
example: Creating directory: /Users/bakthak
example: Creating directory: /Users/bakthak/cookbooks-0
example: Creating configuration file 'solo.rb'
example: Creating JSON attribute file
example: Executing Chef: sh /Users/bakthak/check.sh
Build 'example' finished.
I had a few questions about this:
- Is packer using my local machine to install chef and build the image?
- Looks like the shell script
sh /Users/bakthak/check.sh
is not executed since that script creates a bunch of files in a directory which does not exist after packer build completion.
Thanks for the help :)
Packer will connect and run the "provisioner" on the machine/target identified or created in
"builders":
section. As per the documentation on thefile
builder:So by using this builder, you are not creating a connection to anywhere. However there is a builder called
null
which can be used establish an SSH session and run the provisioner.Consider the example below where
192.168.1.102
is the IP address of my machine (localhost on whichpacker
is running), with the credentials that can SSH to it:That said, it would be better to stick to the default
execute_command
, for thechef-solo
provisioner:and run the script from a Chef resource:
my_cookbook/recipes/default.rb: