You can use jq to join several json files and thus keep snippets that you join together. See https://stackoverflow.com/questions/19529688/how-to-merge-2-json-file-using-jq
On Tue, Jun 11, 2019 at 12:42 PM Nasir Amin <[email protected]> wrote: > Hi, > > I am using Packer version 1.4.1 > What is the best practice to manage generic templates. > We have a few packer template files for different windows versions. The > template's builders section is common and we use var files to pass in any > user variables. > > The reason we are having to keep multiple json template files is due to > the Provisioner sections being different for different types of templates. > > Question: > Is there a way we can use the same template file with just the builders > section. > For provisioners, we can either put them in a separate file and then > somehow inject it into the main tempalte OR > if we can pass in the Provisioners in the form of a json array through a > user variable from a variables file? > > Some of my provisioners are powershell scripts, ansible and windows > restart. Is it possible to pass in provisioners from a variable file like > this? > > > "host_provisioners": [ > { > "type": "powershell", > "inline": [ > "cmd.exe /c powershell.exe Set-ExecutionPolicy Unrestricted > -force", > "a:\\scripts\\Configure-MinorSettings.ps1", > "a:\\scripts\\win2019-setup-ssh.ps1", > "a:\\scripts\\Setup-Docker.ps1" > ] > }, > { > "type": "windows-restart", > "restart_check_command": "powershell -command \"& {Write-Output 'Guest > Restarted Successfully.'}\"" > } > ] > } > > > Then in the main template file where my builders are, I do this: > > "provisioners": "{{user host_provisioners }}" > > It seems like you have to put provisioners and builders in the same file. > It would be good if we can do on one of the following and if it is already > possible: > > > - Isolate builders and provisioners into separate files and then > combine them in the packer build command with a flag like > --provisioner-file=<path to file> > - OR Allow passing the provisioners from a variables file. > > The first approach will probably be more flexible. > > What is the best practice on structuring and managing multiple templates > or making your templates generic? As things stand, it seems impossible to > apply DRY principles to Packer. > > I'll really appreciate any guidance on this please as our packer scripts > and templates are becoming a bit hard to scale and maintain. > I see packer will eventually support HCL2 which should make some of the > things easier e.g. conditional provisioners etc > https://github.com/hashicorp/packer/issues/1768 > > > Regards, > > Nas > > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/packer-tool/ea90623a-2da1-453e-969c-0e7c39a04969%40googlegroups.com > <https://groups.google.com/d/msgid/packer-tool/ea90623a-2da1-453e-969c-0e7c39a04969%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt8xA2rGGJMA%3Ds3Q-xrP_EC-HBh2%3Dih6cGzZ%3DSnwQ-c0eg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
