Can't rely say, this works for me:
{
   "variables" : {
      "aws_access_key" : ""
   },
   "builders": [
     {
       "type": "docker",
       "image": "ubuntu",
       "export_path": "/dev/null"
     }
   ],
   "provisioners" : [
      {
         "type" : "shell",
         "environment_vars" : [
            "AWS_ACCESS_KEY_ID={{user `aws_access_key`}}"
         ],
         "inline" : [
            "echo AWS_ACCESS_KEY_ID is $AWS_ACCESS_KEY_ID",
            "echo '{{user `aws_access_key`}}'"
         ]
      }
   ]
}

$ packer build -var aws_access_key="AIKA" env_var_inline.json
docker output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu
    docker: Using default tag: latest
    docker: latest: Pulling from library/ubuntu
    docker: Digest:
sha256:2d44ae143feeb36f4c898d32ed2ab2dffeb3a573d2d8928646dfc9cb7deb1315
    docker: Status: Image is up to date for ubuntu:latest
==> docker: Starting docker container...
    docker: Run command: docker run -v
/Users/rickardvonessen/.packer.d/tmp/packer-docker054886684:/packer-files
-d -i -t ubuntu /bin/bash
    docker: Container ID:
288baec51ee59c3d1572606c2119ef6143ac97adb9fcfa0fb7dcecb01fcefa11
==> docker: Provisioning with shell script:
/var/folders/z6/z83mb59576b4f5ngh_tw6crc0000gp/T/packer-shell921548401
    docker: AWS_ACCESS_KEY_ID is AIKA
    docker: AIKA
==> docker: Exporting the container
==> docker: Killing the container:
288baec51ee59c3d1572606c2119ef6143ac97adb9fcfa0fb7dcecb01fcefa11
Build 'docker' finished.

==> Builds finished. The artifacts of successful builds are:
--> docker: Exported Docker file: /dev/null

Could you try that and post the output when running this if it doesn't work.


On 3 November 2016 at 02:49, <[email protected]> wrote:

> Hello everyone,
>
> I started using packer recently and so far faced an issue with passing
> variables while using shell provisioner.
> The following example was running on Packer 0.11.0 on Ubuntu16.04 and it
> was provisioning CentOS 6.7 host.
>
> Here is an example of my code:
>
>   "variables": {
>     "aws_access_key": "",
>     "aws_secret_key": ""
>   }
>
>   "provisioners": [
>     {
>       "type": "shell",
>
>       "environment_vars":[
>         "PACKER_SERVERNAME=packer_test",
>         "AWS_ACCESS_KEY_ID={{user `aws_access_key`}}",
>         "AWS_SECRET_ACCESS_KEY={{user `aws_secret_key`}}"
>       ],
>
>       "inline": [
>         "echo AWS_ACCESS_KEY_ID is $AWS_ACCESS_KEY_ID",
>         "echo '{{user `aws_access_key`}}' > /tmp/aws_access_key",
>         "sudo bash packer_bootstrap.sh"
>       ]
>
>     }]
>
>
> So, here I'm defining environment variables directly for
> *PACKER_SERVERNAME* and using hiding method for *AWS_ACCESS_KEY*.
> However upon checking this variable value during the next step in "inline"
> command - there is nothing in it.
> Its output is just like that:
>
> *==> amazon-ebs: Provisioning with shell script:
> /tmp/packer-shell656434894*
> *    amazon-ebs: AWS_ACCESS_KEY_ID is*
>
> And /tmp/aws_access_key file is also empty.
>
> Would you please advice what is wrong in that configuration, why variables
> aren't going through and how to make it working.
>
> Thank you,
> Maxim
>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/packer-tool/e66ad4bf-76be-40ac-9d13-67cd4b930010%40googlegroups.com
> <https://groups.google.com/d/msgid/packer-tool/e66ad4bf-76be-40ac-9d13-67cd4b930010%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/CALz9Rt9nAHdS%3Dt7_DksgBq18r5NdjJod0ZSrFwvjGxPJYxNkAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to