Hello there!
I’m trying to build an application image from the golden image (AMI ID). But, if I variablize the source AMI ID, it ended up with some errors.
Working:
export source_ami=ami-02961139e1c00ed16
packer build -machine-readable -var aws_source_ami="$source_ami" app_image.json
NOT Working:
export source_ami=$(curl -ks GET https://consul01/v1/kv/os/base/images/base/rhel_7.7/20200422?raw)
packer build -machine-readable -var aws_source_ami="$source_ami" app_image.json
Packer log:
Packer.log
05:58:44.422 1590472724,,ui,error,\n==> Some builds didn't complete successfully and had errors:
05:58:44.425 1590472724,amazon-ebs,error,Error querying AMI: InvalidAMIID.Malformed: Invalid id: "<!-- IE friendly error message walkround. \n if error message from server is less than \n 512 bytes IE v5+ will use its own error \n message instead of the one returned by \n server. --> \n \n \n \n \n \n \n<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">html%!(PACKER_COMMA)body{height:100%;padding:0;margin:0;}.oc{display:table;width:100%;height:100%;}.ic{display:table-cell;vertical-align:middle;height:100%;}div.msg{display:block;border:1px solid #30c;padding:0;width:500px;font-family:helvetica%!(PACKER_COMMA)sans-serif;margin:10px auto;}h1{font-weight:bold;color:#fff;font-size:14px;margin:0;padding:2px;text-align:center;background: #30c;}p{font-size:12px;margin:15px auto;width:75%;font-family:helvetica%!(PACKER_COMMA)sans-serif;text-align:left;}</style><title>504 DNS look up failed</title></head><body><div class="oc"><div class="ic"><div class="msg"><h1>504 DNS look up failed</h1><p><p>The webserver reported that an error occurred while trying to access the website. Please click <u><a href="javascript:history.back()">here</a></u> to return to the previous page.</p>\n<p>\n URL: HTTP://GET/<br />\n <br/>User name: \n <br/>Group name: \n</p></p></div></div></div></body></html>\nami-02961139e1c00ed16" (expecting "ami-...")\n status code: 400%!(PACKER_COMMA) request id: 29276d9a-d184-45ed-a564-13164e6b93ca
05:58:44.428 1590472724,,ui,error,--> amazon-ebs: Error querying AMI: InvalidAMIID.Malformed: Invalid id: "<!-- IE friendly error message walkround. \n if error message from server is less than \n 512 bytes IE v5+ will use its own error \n message instead of the one returned by \n server. --> \n \n \n \n \n \n \n<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">html%!(PACKER_COMMA)body{height:100%;padding:0;margin:0;}.oc{display:table;width:100%;height:100%;}.ic{display:table-cell;vertical-align:middle;height:100%;}div.msg{display:block;border:1px solid #30c;padding:0;width:500px;font-family:helvetica%!(PACKER_COMMA)sans-serif;margin:10px auto;}h1{font-weight:bold;color:#fff;font-size:14px;margin:0;padding:2px;text-align:center;background: #30c;}p{font-size:12px;margin:15px auto;width:75%;font-family:helvetica%!(PACKER_COMMA)sans-serif;text-align:left;}</style><title>504 DNS look up failed</title></head><body><div class="oc"><div class="ic"><div class="msg"><h1>504 DNS look up failed</h1><p><p>The webserver reported that an error occurred while trying to access the website. Please click <u><a href="javascript:history.back()">here</a></u> to return to the previous page.</p>\n<p>\n URL: HTTP://GET/<br />\n <br/>User name: \n <br/>Group name: \n</p></p></div></div></div></body></html>\nami-02961139e1c00ed16" (expecting "ami-...")\n status code: 400%!(PACKER_COMMA) request id: 29276d9a-d184-45ed-a564-13164e6b93ca
05:58:44.428 1590472724,,ui,say,\n==> Builds finished but no artifacts were created.
05:58:44.783 2020/05/26 05:58:44 waiting for all plugin processes to complete...
05:58:44.787 2020/05/26 05:58:44 /usr/local/bin/packer: plugin process exited
05:58:44.788 2020/05/26 05:58:44 /usr/local/bin/packer: plugin process exited
05:58:44.788 2020/05/26 05:58:44 /usr/local/bin/packer: plugin process exited
05:58:44.788 2020/05/26 05:58:44 /usr/local/bin/packer: plugin process exited
05:58:44.788 2020/05/26 05:58:44 /usr/local/bin/packer: plugin process exited
This file has been truncated. show original
In between, I thought of using the consul_key
function, but even that throws an error like Error initializing core: error interpolating default value for 'aws_source_ami': template: root:1: function "consul_key" not defined
. I’m not sure if it is the correct way to use it. Please suggest on that too.
Code:
{
"variables": {
"aws_source_ami" : "{{consul_key `os/base/images/base/rhel_7.7/20200422`}}",
},
"description" : "This will create the baked VM image",
"builders": [{
"source_ami" : "{{user `aws_source_ami`}}"
}]
}
Command:
packer build -machine-readable app_image.json