parse AMI id from packer output

2,555 views
Skip to first unread message

Weng Wilson

unread,
Mar 25, 2014, 3:50:51 AM3/25/14
to packe...@googlegroups.com
Hi,

I want to get AMI id (multiple AMIs from parallel building) from packer output and maybe record it to a json-format file so the next automation process can get it. I tried to use -machine-readable but not really get how to read the output easily.  Could anyone suggest a convenient way to do that? 

Thanks
Wilson

Demetri Mouratis

unread,
Mar 25, 2014, 3:21:11 PM3/25/14
to packe...@googlegroups.com
Ha. I came here to ask the same question.

Building AMIs with packer out of Jenkins. I need to have packer output the AMI ID to a file which I can then read (or some other work flow, just an idea). The next step for me is to run a aws cloudormation template passing in the ami. Then, update the resulting template to S3.

Any ideas appreciated.

-D

Kyle Gochenour

unread,
Mar 25, 2014, 4:05:15 PM3/25/14
to packe...@googlegroups.com
I was able to get the following to pull the AMI id from the packer output, assuming the output is dropped to a file. But I can not figure out how to get Jenkins to read the packer output from the build successfully.

awk -F"," '$3 ~/artifact/ && $5 ~/id/ && $6 ~/ami/ {print substr($6,length($6)-11,length($6))}' <outpuffilename>

Dan Rigsby

unread,
Apr 27, 2014, 3:44:31 PM4/27/14
to packe...@googlegroups.com
Im looking for the same.  It would be nice if there was an option on the AMI builder itself to specify the output file to write the AMI Id out to.  Until, then i will also be looking at scrapping the console output, but i really need to it also write out to our Bamboo server.

Dan Rigsby

unread,
Apr 27, 2014, 7:37:30 PM4/27/14
to packe...@googlegroups.com
This worked for me:

It will write the output to stdout so it can be picked up my jenkins or bamboo or whatever.  It also writes to a output.txt file that used by the second command to write just the AMI ID to 'ami.txt'.


On Tuesday, March 25, 2014 3:50:51 AM UTC-4, Weng Wilson wrote:

Alexander Gray II

unread,
Dec 5, 2014, 5:33:31 AM12/5/14
to packe...@googlegroups.com
Thanks for finding a solution for this.  Much appreciated.  If packer ever changes the output, then these parsing commands will fail.  Too bad packer does not produce a json output (or something similar) to get this information.
Reply all
Reply to author
Forward
0 new messages