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

User variables not usable in Builder name #296

Closed
fnichol opened this issue Aug 15, 2013 · 4 comments
Closed

User variables not usable in Builder name #296

fnichol opened this issue Aug 15, 2013 · 4 comments
Labels

Comments

@fnichol
Copy link

fnichol commented Aug 15, 2013

I may have over-DRYed things here, but found that the name attributes doesn't get evaluated for user variables:

> cat template_aws.json
{
  "variables": {
    "name_prefix": "cool-",
    "platform": "beans"
  },
  "builders": [
    {
      "name": "{{user `name_prefix`}}{{user `platform`}}_aws",
      "type": "amazon-ebs",
      "region": "us-east-1",
      "source_ami": "ami-de0d9eb7",
      "instance_type": "t1.micro",
      "ssh_username": "ubuntu",
      "ami_name": "packer-example {{timestamp}}"
    }
  ]
}
> packer build template_aws.json
{{user `name_prefix`}}{{user `platform`}}_aws output will be in this color.

==> {{user `name_prefix`}}{{user `platform`}}_aws: Creating temporary keypair for this instance...
==> {{user `name_prefix`}}{{user `platform`}}_aws: Creating temporary security group for this instance...
==> {{user `name_prefix`}}{{user `platform`}}_aws: Authorizing SSH access on the temporary security group...
==> {{user `name_prefix`}}{{user `platform`}}_aws: Launching a source AWS instance...
==> {{user `name_prefix`}}{{user `platform`}}_aws: Waiting for instance (i-9d9c78ff) to become ready...

Thanks again for such awesome tooling that helps me each and every day!!

@mitchellh
Copy link
Contributor

Oof, I'd like to make this work. Tagging it. Thanks.

@bscofield
Copy link

This just bit me too, FWIW

@bscofield
Copy link

Incidentally, it looks like the interpolation doesn't work for the key in the following case, either:

{
  "variables": {
     "role": "statsd"
   },
  "provisioners": [
    {
      "type": "shell",
      "scripts": ["../scripts/base.sh"],
      "override": {
        "{{user `role`}}": { "execute_command": "echo 'vagrant'|sudo -S sh '{{.Path}}'" }
      }
    }
  ],
  ...
}
$ > packer build template.json
....
==> statsd: Provisioning with shell script: ../scripts/base.sh
    statsd: E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
    statsd: E: Unable to lock directory /var/lib/apt/lists/
    statsd: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
    statsd: E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
    statsd: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
    statsd: E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
    statsd: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
    statsd: E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
    statsd: E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
    statsd: E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
    statsd: E: Could not open lock file /var/cache/apt/archives/lock - open (13: Permission denied)
    statsd: E: Unable to lock the download directory
    statsd: mv: cannot move `/tmp/vagrant' to `/etc/sudoers.d/vagrant': Permission denied

fnichol added a commit to fnichol/packer-templates that referenced this issue Oct 5, 2013
@mitchellh
Copy link
Contributor

Fixed, finally. :)

@ghost ghost locked and limited conversation to collaborators Apr 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants