0

I have a script in provisioner's section of my Packer template, which requires the variable $ami_name. Is there any way that I can reliably get this information?

Provisioners section

"provisioners": [
    {
      "type":            "shell",
      "execute_command": "sudo {{.Vars}} bash '{{.Path}}'",
      "scripts": [
        "./scripts/packer/myscript.sh"
      ]
    }
  ]

./scripts/packer/myscript.sh:

#!/usr/bin/env bash
aminame=$ami_name
make_an_external_call "$aminame"

Here I need to get the ami_name from Packer. As this provisioners stage happens after Packer does a pre-validation of AMI Name, there should be a way I can get this right?

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
sibi s
  • 11
  • 2
  • Is Packer **creating** an AMI - and you're then trying to get that AMI name? Or is this coming from elsewhere and you just want to pass in the `$ami_name` environment variable? – TJ Biddle Dec 01 '17 at 23:34
  • @TJBiddle I dont want to insert ami_name variable into packer json. I actually wanted to get the ami_name (already inserted by user) and use it in my script which will be run as part of provisioners (I have instructed all users to add this script as part of provisioners). So the challenge was to get the ami name inside that script, as packer does not provide any env or something to find the target ami_name. – sibi s Dec 03 '17 at 06:46
  • Possible duplicate of [How to pass argument in packer provision script?](https://stackoverflow.com/questions/47596369/how-to-pass-argument-in-packer-provision-script) – TJ Biddle Dec 03 '17 at 16:31

0 Answers0