Copying files to a Build Folder

1,361 views
Skip to first unread message

Vijay Mehta

unread,
Mar 8, 2016, 4:54:03 PM3/8/16
to Packer
I have a few files which need to be copied to Packer build Folder  packer-VMware-iso.
These files need to be copied and renamed.
I can do this using an external batch file or powershell script but I want it to be included as part of my packer configuration.
How and when should I do this?
Assume the file is someconfig.txt in the packer-VMware-iso.
At the end someconfig.txt should get copied at the end and renamed to someconfig.cfg residing along with vmdk,vmx files within this folder I want this file to exist too.
Note this file needn't be copied to the vm its to be copied to the output folder instead.
Waiting for a reply.

Alvaro Miranda Aguilera

unread,
Mar 8, 2016, 6:07:08 PM3/8/16
to packe...@googlegroups.com
Hello, 

For file manipulation, you can try:
For during the build you can use local-shell provisioner.
After the build local-shell is also available in the post-provisioner.


if the result will be a vagrant box ie. file.box, then you can use vagrant post-provisioner to include files.

Hope this helps.
Alvaro.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/8c126e4b-2049-4326-9877-d9dc4b620df9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Mehta

unread,
Mar 9, 2016, 6:48:31 PM3/9/16
to Packer
Do we have an example of this somewhere ?
A file  foo.txt is in a folder ./Files needs to get copied to ./Packer-output and then renamed as foo.cfg inside the output folder that is it. 
    "post-processors": [
        {
            "type": "shell-local",
            "command"   ?????? need some example 
        },

Alvaro Miranda Aguilera

unread,
Mar 9, 2016, 7:52:14 PM3/9/16
to packe...@googlegroups.com

On Thu, Mar 10, 2016 at 12:48 PM, Vijay Mehta <vjay...@gmail.com> wrote:
    "post-processors": [
        {
            "type": "shell-local",
            "command"   ?????? need some example 
        },

It will be executed in the os you are running.

so if you have to do:

cp Files/too.txt Packer-output/foo.cfg

That is you need to run.

Packer will run that command on the host OS.

Alvaro.

Vijay Mehta

unread,
Mar 9, 2016, 8:43:36 PM3/9/16
to packe...@googlegroups.com
   "post-processors": [
        {
            "type": "shell-local",
            "command":["copy ./FILES/sys.txt ./newmachine/Win764.cfg"],
            "command":["copy ./FILES/sys.log ./newmachine/Win764.ini"]
        },
packer build --force windows_7.json
Failed to initialize build
Win764: post-processor type not found: shell
Win764 output will be in this color.


==> Builds finished but no artifacts were created.

D:\Packer\W7\W7-64>packer build --force windows_7.json
Failed to initialize build
Win764: post-processor type not found: shell-local
Win764 output will be in this color.



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/HpzjnX52C6g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAHqq0ezk%2By5qJ02aDOdpsZa5ytbVrV9_gh8iWVd6_upz9cME%3DA%40mail.gmail.com.

Alvaro Miranda Aguilera

unread,
Mar 9, 2016, 9:40:45 PM3/9/16
to packe...@googlegroups.com
hello,

Can you check you are on latest/current version.

and also, review syntax like this:


Thanks
Alvaro.

You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAHZwWNNNt6Ey9zj04nuECOFnpDV0ndr6ds8tDDSgtg397C6cag%40mail.gmail.com.

Vijay Mehta

unread,
Mar 31, 2016, 11:08:49 PM3/31/16
to Packer
Alvaro
I have some post process to take care of in the image output folder it is to run an executable with arguments.
Now to do that I tried this
  TRY-1
    "post-processors": [
         {
          "type": "compress",
          "keep_input_artifact": true,
          "output": "{{.BuildName}}.zip"
          },
          {
           "type": "shell-local",
            "command": "./Files/copyutil.exe {{user `imgName`}}"
          }
     ],
====================================================================================================================
* unknown configuration key: "command"
    "post-processors": [
         {
          "type": "compress",
          "keep_input_artifact": true,
          "output": "{{.BuildName}}.zip"
          },
          {
           "type": "shell-local",
            "execute_command": "./Files/copyutil.exe {{user `imgName`}}"
          }
     ],
* Either a script file or inline script must be specified."
I know I am missing something could I get some tips on this.note the `imgName` is required to search a folder
======================================================================================================================

Alvaro Miranda Aguilera

unread,
Apr 1, 2016, 1:16:32 AM4/1/16
to packe...@googlegroups.com
hello,

You can pass argument overriding the execute_command:

ie:

execute_command (string) - The command to use to execute the script. By default this is chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}. The value of this is treated as configuration template. There are two available variables:Path, which is the path to the script to run, and Vars, which is the list ofenvironment_vars, if configured.



 chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }} <argument1> <argument2>.



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

Vijay Mehta

unread,
Apr 1, 2016, 1:34:44 AM4/1/16
to Packer
What is chmod for?
Can you give me an example or correct whatever I have done below accommodating
  {
           "type": "shell-local",
            "execute-command": ["./Files/copyutil.exe {{user `imgName`}}"]
Reply all
Reply to author
Forward
0 new messages