Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolate builder type, and only run provisioner when matched #5696

Closed
bleloch opened this issue Dec 12, 2017 · 2 comments
Closed

Interpolate builder type, and only run provisioner when matched #5696

bleloch opened this issue Dec 12, 2017 · 2 comments
Labels
bug core Core components of Packer stage/duplicate

Comments

@bleloch
Copy link

bleloch commented Dec 12, 2017

We currently have a template to provision a base image for our applications, which I'd like to run a specific provisioner for based on the builder type. This would allow us to have to run multiple 'configurations' into the same template and build one version of the image with Enhanced Networking and one without.

I'd like to be able to pass the $PROVISIONER variable containing 'Amazon-Machine-Base-Image' or 'Amazon-Machine-Enhanced-Networking-Image' to Packer, so that only the provisioner that matches the "name" variable is run. Here's the template I'm working with:

{
	"variables":
		{
			"ami_id_source": "{{env `BASE_IMAGE`}}",
			"aws_access_key_id": "{{env `AWS_ACCESS_KEY_ID`}}",
			"aws_secret_access_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
			"region": "{{env `AWS_REGION`}}",
			"provisioner_name": "{{env `PROVISIONER`}}",
			"sriov_enabled": "{{env `SRIOV_ENABLED`}}"
		},
	"builders": [
				{
					"name": "{{user `provisioner_name`}}",
					"type": "amazon-ebs",
					"access_key": "{{user `aws_access_key_id`}}",
					"secret_key": "{{user `aws_secret_access_key`}}",
					"region": "{{user `region`}}",
					"ami_regions": "{{user `region`}}",
					"source_ami_filter": {
    						"filters": {
      							"virtualization-type": "hvm",
							"name": "CentOS Linux 7 x86_64 HVM EBS*",
      							"root-device-type": "ebs"
    						},
    						"owners": ["410186602215"],
    						"most_recent": true
					},
					"instance_type": "t2.small",
					"sriov_support": "{{user `sriov_enabled`}}",
					"ami_block_device_mappings": [ {
						"device_name": "/dev/sda1",
						"volume_size": 8,
						"delete_on_termination": true
					} ],
					"launch_block_device_mappings": [ {
						"device_name": "/dev/sda1",
						"volume_size": 8,
						"delete_on_termination": true
					} ]
				}
				],
	"provisioners": [
		{
		  "only": ["Amazon-Machine-Base-Image"],
		  "type": "shell",
		  "inline": [
			"sleep 30",
			"sudo yum install epel-release -y; sudo yum update -y; sudo yum install ansible python-setuptools python-dateutil python-pip python-devel -y"
		  ]
		},
		{
	 	  "only": ["Amazon-Machine-Enhanced-Networking-Base-Image"],
	          "type": "shell",
		  "script": "Scripts/Shell/enhanced_networking.sh"		
		}
	]
}

I have verified that the provisioner_name variable is being populated properly and being passed to Packer. It would seem that Packer isn't aware of the contents of this variable when it parses the provisioners, as it throws this error:

* provisioner 1: 'only' specified builder 'Amazon-Machine-Base-Image' not found
* provisioner 2: 'only' specified builder 'Amazon-Machine-Enhanced-Networking-Base-Image' not found

Could someone confirm that it is expected behaviour for the builder type to be constant, and if so, is there a solution for this where we can keep just one template for both enhanced and non-enhanced networking images?

I am running Packer 1.1.0 on Amazon Linux 2017.03.

@rickard-von-essen rickard-von-essen added bug core Core components of Packer stage/duplicate labels Dec 12, 2017
@rickard-von-essen
Copy link
Collaborator

Thanks for reporting this. This is a duplicate of #2651.

@ghost
Copy link

ghost commented Apr 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core Core components of Packer stage/duplicate
Projects
None yet
Development

No branches or pull requests

2 participants