Packer user variables not working

1,541 views
Skip to first unread message

Doug T

unread,
Aug 21, 2015, 3:11:08 PM8/21/15
to Packer
I'm having some trouble with the user variable function of packer. This is very important to our infrastructure because we rely on a flexible ansible playbook to push out roles to docker containers. I would like to make it possible to have 1 template to allow for easier management. The following does not work. 

{
  "variables": 
    {   
     "role": ""
    },  

  "builders": ....

  "provisioners": [
    {   
      "type": "ansible-local",
      "role_paths": "/ansible/roles/{{user 'role'}}/",
      "playbook_file": "/ansible/playbooks/pushroledocker.yml",
      "extra_arguments": "-e roletag={{user 'role'}}"
    }   
  ],  

Then I run 'packer build -var 'role=docker' template.json and it errors,


invalid 'extra_arguments': template: root:1: malformed character constant: 'role' in:
-e roletag={{user 'role'}}


In multiple attempts, it also errors out on the rolepath as well. Is it possible to replace vars in this fashion? 



Doug T

unread,
Aug 21, 2015, 3:12:24 PM8/21/15
to Packer
I should mention:

Packer version 0.8.5

Alvaro Miranda Aguilera

unread,
Aug 21, 2015, 8:46:31 PM8/21/15
to packe...@googlegroups.com
Hello

looks like the quotes you are using aren't the correct ones

it should be user `variable`

note are the quotes ` and not simple quotes '

I know this quote is not in every keyboard layout

Can you test?

Alvaro.
> --
> 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 packer-tool...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/packer-tool/b21dc0db-3abb-49f8-837a-14364bb50ca6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Doug T

unread,
Aug 24, 2015, 10:28:13 AM8/24/15
to Packer
Weird, but works! 

Thanks for the help. 
Reply all
Reply to author
Forward
0 new messages