Thanks Alvaro. Basically I need to get the target AMI Name (the one that is given to packer in "*builders*" section). Packer will use this ami name while creating image right. May be I need to clarify a few things:
The packer json file will be submitted by the user. I will inject a script in provisioners section, which will do few things. I can always parse the packer json to find the *ami_name* variable in *builders* section and pass it as a parameter to my script in provisioners. But if the user has passed a dynamic value for ami_name(something suffixed with -timestamp for eg. or a user variable), then I will get to know about the ami name only after the build starts. So somehow I need to findout the target AMI Name used by packer from within my script in provisioners. Is there any environment variable or something pushed by packer, which will allow me to get this value? On Wednesday, November 29, 2017 at 2:44:25 PM UTC+5:30, Alvaro Miranda Aguilera wrote: > > you want to feed there the AMI name of the current running instance? > > Your script should be able to get this from the metadata > > > http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html > > > *curl http://169.254.169.254/latest > <http://169.254.169.254/latest>/meta-data/ami-id* ami-12345678 > > Alvaro. > > > On Wed, Nov 29, 2017 at 9:14 AM, sibi das <[email protected] <javascript:>> > wrote: > >> Hi, >> >> I am running a script in provisioners section, which requires AMI name >> used by packer. I know the pre-validation of AMI name by packer happens >> before this stage. Is there any reliable way in which I can get the >> ami_name inside my script ? >> >> My script would go like this: >> >> "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" >> >> -- >> 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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/packer-tool/a88ca74e-0415-4b96-ad5a-340af42f0d36%40googlegroups.com >> >> <https://groups.google.com/d/msgid/packer-tool/a88ca74e-0415-4b96-ad5a-340af42f0d36%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/97be545a-4ade-47a0-ae80-4b36082eccca%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
