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

-only fails with interpolated builder name #858

Closed
strcrzy opened this issue Jan 27, 2014 · 7 comments
Closed

-only fails with interpolated builder name #858

strcrzy opened this issue Jan 27, 2014 · 7 comments
Labels
bug core Core components of Packer

Comments

@strcrzy
Copy link
Contributor

strcrzy commented Jan 27, 2014

might be related to #296

this seems to still be broken, at least with the -only flag

vagrant@packer-virtualbox:/Users/jwb/hatchery$ packer build  -only=docker-base -var 'target=base' -var 'docker_source_image=tvservices/ubuntu-ansible:13.04' templ.json
Unknown build in 'only' flag: docker-base
{
   "variables":{
      "aws_key":"{{env `AWS_ACCESS_KEY_ID`}}",
      "aws_secret":"{{env `AWS_SECRET_ACCESS_KEY`}}",
      "target":"",
      "aws_region":"",
      "aws_source_ami":"",
      "aws_instance_type":"",
      "docker_registry":"",
      "docker_source_image":""
   },
   "provisioners":[
      {
         "only":[
            "docker-{{user `target`}}"
         ],
         "type":"shell",
         "script":"scripts/apt_sources_docker.sh"
      },
      {
         "extra_arguments":[
            "-vvv"
         ],
         "playbook_paths":[
            "ansible/playbooks/{{user `target`}}"
         ],
         "playbook_file":"ansible/{{user `target`}}.yml",
         "command":"stdbuf -oL -eL ansible-playbook",
         "type":"ansible-local"
      }
   ],
   "builders":[
      {
         "image":"{{user `docker_source_image`}}",
         "type":"docker",
         "name":"docker-{{user `target`}}",
         "run_command":[
            "run",
            "-privileged",
            "-d",
            "-i",
            "-t",
            "-v",
            "{{.Volumes}}",
            "{{.Image}}",
            "/bin/bash"
         ],
         "export_path":"/tmp/packer-docker-{{user `target`}}-{{timestamp}}.tar"
      }
   ]
}
@mconigliaro
Copy link

Same here.

@mitchellh mitchellh added the bug label Feb 22, 2014
@mitchellh
Copy link
Contributor

Thanks, will check it out.

@mtthwcmpbll
Copy link

I also ran into this today, and was led to this issue from the mentioned #296 (which looks like the original poster was doing almost exactly what we extracting VM role out as a user variable). I've got a set of build scripts wrapping the invocation of Packer to help developers build logical subsets of our images, but this issue means we'll have to make duplicate templates for now, one for each role. I'd love to be able to combine these into a single parameterized template.

@jantman
Copy link

jantman commented Jul 16, 2014

Yeah, I'm running into this (I believe the same issue) as well where I define in my builder:

"name": "{{user `box_name`}}-{{user `box_version`}}"

and then attempt (in a script provisioner):

  "only": [
    "{{user `box_name`}}-{{user `box_version`}}"
  ],

but the provisioner never runs

@jasonberanek
Copy link
Collaborator

I've replicated the bug, and think I know enough about the problem to work on a fix.

The build name values used to when processing ParseTemplate here do not resolve any user variables or configuration templates. This results in two behaviors:

  • For build names in the builder definition, the -only and -except flags will only match the pattern included in the JSON file, not the processed value (e.g., name will be {{user name}} rather than name_value). If you used the string with the template on the command line, the call will select the proper value.
  • For the build names used in provisioner and post-processor definition only or except attributes, the names used for those attributes match the pattern included in the JSON file, not the processed value (e.g., name will be {{user name}} rather than name_value). In this case, the problem occurs because when packer evalutes whether a provisioner or post-processor applies based on those statements, it compares the attributes against the processed value (e.g., comparing {{user name}} against name_value. This match fails and should result in either A) the provisioner or post-processor never applying in the case an only attribute is set or B) the provisioner or post-processor applying to all builds irrespective of any builds it shouldn't based on the except attribute.

I need to get my development workstation in order before I can put this together, so if anyone wants to dig in and provide a pull request in the interim please do.

strcrzy added a commit to strcrzy/packer that referenced this issue Aug 9, 2014
strcrzy added a commit to strcrzy/packer that referenced this issue Aug 9, 2014
strcrzy added a commit to strcrzy/packer that referenced this issue Aug 9, 2014
jasonberanek added a commit to jasonberanek/packer that referenced this issue Aug 10, 2014
@nchammas
Copy link
Contributor

I'm seeing this issue as well. Builders specified in the only clause in the template don't run if their names depend on template variables. It's not limited to the -only command line parameter.

@mitchellh mitchellh added the core Core components of Packer label Oct 28, 2014
sethvargo added a commit that referenced this issue Nov 26, 2014
fix build name ConfigTemplate processing [GH-858]
@mitchellh
Copy link
Contributor

This is fixed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core Core components of Packer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants