Access the packer http server from shell provisioner?

1,680 views
Skip to first unread message

Paul Steinbach

unread,
May 7, 2014, 4:56:16 PM5/7/14
to packe...@googlegroups.com
I'm following the very common pattern of using "http_directory" in a packer builder, to serve up a CentOS kickstart file.  Like this:

"boot_command": [
        "<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
      ],
"http_directory": "http",

My question:  Can I put other files into the http folder, and access them from my shell provisioning scripts?

Assuming that the http server is still running during the provisioning step, everything seems to hinge on getting the values of HTTPIP and HTTPPort into the running script.  I'm having no luck so far.  I export .Vars into my provisioner as described in the docs, but alas, it's not working.  This is what I have in my packer file:

"override": {
        "vmware-iso": {
          "execute_command": "echo 'packer' | {{ .Vars }} sudo -E -S sh '{{ .Path }}'"
        }
      },

Then I do this in my script:

wget -P /tmp http://${HTTPIP}:${HTTPPort}/file.txt

Any suggestions appreciated!  Cheers,
Paul

Alvaro Miranda Aguilera

unread,
May 7, 2014, 7:32:29 PM5/7/14
to packe...@googlegroups.com
packer have a way to copy files, have you tried that?


--
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.
For more options, visit https://groups.google.com/d/optout.

Paul Steinbach

unread,
May 8, 2014, 11:41:34 AM5/8/14
to packe...@googlegroups.com
Hi Alvaro,

Thank you very much for the suggestion.  In the end I ran a simple http server using Python, and use wget in the provisioning script to pull down what the script needs.

Longer term, I think I need to break the work into two pieces: Do the first part with packer, to make a base box.  Then, use vagrant with shared folders for the rest of the work - this probably fits the overall workflow better anyway.

Thanks!
Paul

Paul Steinbach

unread,
May 9, 2014, 9:57:03 AM5/9/14
to packe...@googlegroups.com
Hi Alvaro,

I re-read the docs and found the file provisioner.  Here's what I'm using to copy files to the VM:

"provisioners": [
    {
      "type": "file",
      "source": "./file.txt",
      "destination": "/tmp"
    },
   ... etc...

Thanks!
Paul

On Wednesday, May 7, 2014 7:32:29 PM UTC-4, Alvaro Miranda Aguilera wrote:

Alvaro Miranda Aguilera

unread,
May 10, 2014, 12:38:59 AM5/10/14
to packe...@googlegroups.com
yes, thats way easier to use vs webserver + wget

glad you had the chance to test it.

Alvaro.
Reply all
Reply to author
Forward
0 new messages