How can you modularize the json template for a Packer project?

39 views
Skip to first unread message

Tyler McAdams

unread,
Oct 18, 2018, 12:42:53 PM10/18/18
to Packer
I have a situation where I would like to be able to provide, not provide the chef provisioner as part of a packer build. I would also like to be able to specify either an ubuntu build or a debian build. Is there a way to break these prices up in to separate json files so that they could be called a optional variables for a build? Similar to the var-file option.... or maybe with the var-file option? 

Alvaro Miranda Aguilera

unread,
Oct 19, 2018, 5:47:08 AM10/19/18
to packe...@googlegroups.com
Hello

you can put into variables all the info for ubuntu into 

ubuntu.json

and all the debian into

debian.json

then use

packer build -var-file ubuntu.json template.json


if you need to use this on the provisioner, say you got different chef playbooks, you could use then


{
  "variables": {
    "build_name": "",
    ..
  },
  },
  "builders": [
    {
      "name": "{{ user `build_name` }}",
      ..
      "type": "virtualbox-iso"
    }
  ],
  "provisioners": [
    {
      "only": "ubuntu"
      ...
    }
  ],
  "provisioners": [
    {
      "only": "debian"
      ..
    }
  ]
}

just add a variable to each json and the template for build_name

hope this helps.

alvaro.

Rickard von Essen

unread,
Oct 19, 2018, 7:10:33 AM10/19/18
to packe...@googlegroups.com
Since there might be considerable difference when using different distributions another alternative is to put each builder+dist in its own file and provisioners in another and then use some tool (python, jq, sed, etc) to create the final template from these files.

// Rickard

--
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/CAHqq0ey4kqch6vu79GUKhmy9smo%2BXPNbzfUc83dKqnHDDxEC6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Tyler McAdams

unread,
Oct 19, 2018, 10:58:54 AM10/19/18
to Packer
This is good stuff... I also just wanted to give people the option to include the chef run or not... so they could still build either a debian or ubuntu box... but if they don't like / want to run chef they could keep that completely out of the build process. Maybe also give them the option to substitute the chef run with an ansible play book, or a puppet run.. .etc
Reply all
Reply to author
Forward
0 new messages