Reputation: 1733
I have a base AMI which contains java and tomcat (ami-c1f3e7a6
). My application stack consists of 6 separate java apps based on my base AMI, and I am using packer to create the 6 separate AMIs. The ansible playbook app_playbook.yml
downloads the war file from S3 straight into the tomcat/webapps directory. My packer JSON is:
{
"variables": {
"war_file": ""
},
"builders": [{
"type": "amazon-ebs",
"region": "eu-west-1",
"source_ami": "ami-c1f3e7a6",
"instance_type": "t2.small",
"ssh_username": "ec2-user",
"ami_name": "app-{{user `war_file`}}-{{timestamp}}"
}],
"provisioners": [{
"type": "ansible",
"playbook_file": "ansible/app_playbook.yml",
"extra_arguments": "--extra-vars 'war_file={{user `war_file`}}'"
}]
}
At the command line I am doing:
packer build -var 'war_file=release123/application_1.war' tomcat.json
packer build -var 'war_file=release123/application_2.war' tomcat.json
packer build -var 'war_file=release123/application_3.war' tomcat.json
packer build -var 'war_file=release123/application_4.war' tomcat.json
packer build -var 'war_file=release123/application_5.war' tomcat.json
packer build -var 'war_file=release123/application_6.war' tomcat.json
I have been looking into packer's ability to perform parallel builds to speed up the build process but it looks like the provisioner is run against every builder, and I need a specific variable passed into each builder.
I know I could fork the bash commands to execute the builds in parallel, but I feel like there must be a "packer" way of doing this. Any ideas?
Upvotes: 2
Views: 835
Reputation: 4288
Packer doesn't support running the same builder multiple times. If you want to do that you need to duplicate the builder section for your amazon-ebs
builder and the provisioner section using only
.
This is best done by preprocessing a snippet with some script to create the final template.
Upvotes: 1