Uploading files with `packer push`

240 views
Skip to first unread message

Brian Hicks

unread,
Jul 29, 2015, 5:25:22 PM7/29/15
to Packer
Hey,

I've got my configuration working locally, and now I want to push it to Atlas. I have some roles for an `ansible_local` run that I need to upload, but it doesn't look like they're being taken along for the ride despite being in a file provisioner (config attached below). How can I get these files uploaded so I can have builds with Atlas?

Thanks,
Brian Hicks

{
   
"provisioners": [
       
{
           
"type": "shell",
           
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
           
"scripts": [
               
"{{template_dir}}/scripts/ansible.sh",
               
"{{template_dir}}/scripts/vagrant.sh"
           
]
       
},
       
{
           
"type": "shell",
           
"only": ["virtualbox-iso"],
           
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
           
"script": "{{template_dir}}/scripts/vbox.sh"
       
},
       
{
           
"type": "file",
           
"source": "{{template_dir}}/../roles/",
           
"destination": "/tmp/packer-provisioner-ansible-local/roles/"
       
},
       
{
           
"type": "ansible-local",
           
"playbook_file": "{{template_dir}}/../vagrant.yml",
           
"role_paths": [
               
"{{pwd}}/roles/chronos",
               
"{{pwd}}/roles/collectd",
               
"{{pwd}}/roles/common",
               
"{{pwd}}/roles/consul",
               
"{{pwd}}/roles/consul-template",
               
"{{pwd}}/roles/dnsmasq",
               
"{{pwd}}/roles/docker",
               
"{{pwd}}/roles/handlers",
               
"{{pwd}}/roles/haproxy",
               
"{{pwd}}/roles/logrotate",
               
"{{pwd}}/roles/logstash",
               
"{{pwd}}/roles/marathon",
               
"{{pwd}}/roles/mesos",
               
"{{pwd}}/roles/nginx",
               
"{{pwd}}/roles/vault",
               
"{{pwd}}/roles/zookeeper"
           
],
           
"extra_arguments": ["--tags", "bootstrap"]
       
},
       
{
           
"type": "shell",
           
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
           
"script": "{{template_dir}}/scripts/cleanup.sh"
       
}
   
],
   
"builders": [
       
{
           
"type": "virtualbox-iso",
           
"boot_command": [
               
"<tab> text ks=http://{{.HTTPIP}}:{{.HTTPPort}}/vagrant.cfg<enter><wait>"
           
],
           
"boot_wait": "10s",
           
"disk_size": 20480,
           
"guest_os_type": "RedHat_64",
           
"headless": false,
           
"http_directory": "{{template_dir}}/kickstarts",
           
"iso_urls": [
               
"iso/CentOS-7-x86_64-Minimal-1503-01.iso",
               
"http://centos.mirrors.hoobly.com/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso"
           
],
           
"iso_checksum_type": "sha256",
           
"iso_checksum": "7cf1ac8da13f54d6be41e3ccf228dc5bb35792f515642755ff4780d5714d4278",
           
"ssh_username": "vagrant",
           
"ssh_password": "vagrant",
           
"ssh_port": 22,
           
"ssh_wait_timeout": "10000s",
           
"shutdown_command": "echo 'vagrant' | sudo -S /sbin/halt -h -p",
           
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
           
"virtualbox_version_file": ".vbox_version",
           
"vm_name": "microservices-infrastructure-0.3.2-x86_64",
           
"vboxmanage": [
               
["modifyvm", "{{.Name}}", "--memory", "512"],
               
["modifyvm", "{{.Name}}", "--cpus", "2"]
           
]
       
}
   
],
   
"post-processors": [
       
{
           
"type": "vagrant",
           
"output": "builds/VirtualBox-microservices-infrastructure-0.3.2.box"
       
},
       
{
           
"type": "atlas",
           
"only": ["virtualbox-iso"],
           
"token": "{{user `atlas_token`}}",
           
"artifact": "brianhicks/mi",
           
"artifact_type": "vagrant.box",
           
"metadata": {
               
"created_at": "{{timestamp}}",
               
"provider": "virtualbox"
           
}
       
}
   
]
}


Alvaro Miranda Aguilera

unread,
Jul 29, 2015, 7:09:54 PM7/29/15
to packe...@googlegroups.com
Hello Brian,

When you do a packer push, that create a build object in atlas.

When the build process start, it will create an isolated environment, and the code that was pushed, will be made available to this build environment.

Think in this environment, as a brand new empty machine.

From this environment, the shell/file provisioner will upload files to the new VM Guest being created.

So, checking your template, I am missing some information.

You should have a push block, that define where this push will be stored:

ie:
https://github.com/hashicorp/atlas-packer-vagrant-tutorial/blob/master/template.json#L2-L4

"push": {
"name": "alvaro/build1",
"vcs": true
},

After the packer push, this build object will be created at atlas, and will look like this:



From here, you can click on the Folder Icon, and will show you all the files that were uploaded on the packer push:



There files, will be made available to the isolated environment where packer will run.


For shell provisioner, you can just give the path, and the provisioner will copy the file and execute it.

ie:


"provisioners": [
{
"type": "shell",
"scripts": [
"scripts/base.sh",
"scripts/virtualbox.sh",
"scripts/vmware.sh",
"scripts/vagrant.sh",
"scripts/dep.sh",
"scripts/cleanup.sh",
"scripts/zerodisk.sh"
],

Or you can use a file provisioner to move these files into the guest VM once the machine boots. so the files can be used in a chef/puppet provisioner.

Let me know if this make sense, or I am missing something int he explanation.

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/b65159de-233f-4691-97a0-214a205141f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Hicks

unread,
Jul 30, 2015, 11:15:26 AM7/30/15
to Packer, br...@aster.is
Yep, I forgot the push section in the template. That was it. Thanks!

Reply all
Reply to author
Forward
0 new messages