Closed morazow closed 3 years ago
@morazow I can re-create that issue with the CentOS8 AMI and the below Vagrantfile modification to make that work for the prep-ami:
diff --git a/aws/prep-ami/Vagrantfile b/aws/prep-ami/Vagrantfile
index d09f443..0d16917 100644
--- a/aws/prep-ami/Vagrantfile
+++ b/aws/prep-ami/Vagrantfile
@@ -14,7 +14,19 @@ EOT
load File.expand_path('../../Vagrantfile.aws-credentials', __FILE__)
# Load RPMs that need to be installed on top of the CentOS base image
-load File.expand_path('../../../shared/Vagrantfile.rpms', __FILE__)
+load File.expand_path('../../../shared/Vagrantfile8.rpms', __FILE__)
+
+
+class Hash
+ def slice(*keep_keys)
+ h = {}
+ keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
+ h
+ end unless Hash.method_defined?(:slice)
+ def except(*less_keys)
+ slice(*keys - less_keys)
+ end unless Hash.method_defined?(:except)
+end
# Customize configuration specific settings
Here is the output I get:
$ vagrant package SpectrumScale_base --output SpectrumScale_base.box
==> SpectrumScale_base: Burning instance i-0a13a3c4a393f54d6 into an ami
There was an error talking to AWS. The error message is shown
below:
Malformed => AMI names must be between 3 and 128 characters long, and may contain letters, numbers, '(', ')', '.', '-', '/' and '_'
At first glimpse I do not see any issue as all given names are conforming to the character set specified in the error message. Will try to dig a bit deeper to understand if this is a vagrant-aws issue.
As a side note, I was able to install vagrant-aws on an Ubuntu 20.04 system after installing
sudo apt install libcurl4-openssl-dev
Versions:
$ vagrant --version
Vagrant 2.2.6
$ vagrant plugin list
vagrant-aws (0.7.2, global)
vagrant-libvirt (0.0.45, system)
Hey @hseipp,
Thanks for looking into it!
Yes, I also could not understand why it fails. Since it says between 3 and 128 characters
maybe it does not set the AMI name, this might be new requirement from AWS.
p.s. For now, I manually created AMI from instance, and the rest worked for me with minor issue (commented on #16).
I was able to identify the root cause - it is an issue with this line of code in the Vagrant-aws plugin.
The variable server.tags["Name"]
contains a line break and blank characters that are not accepted by the AWS API.
The following patch fixes the vagrant-aws code so that vagrant package
works again:
--- /home/user/.vagrant.d/gems/2.7.0/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/package_instance.rb 2021-06-23 13:58:10.612642358 +0200
+++ /home/user/.vagrant.d/gems/2.7.0/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/package_instance_fixed.rb 2021-06-23 13:59:10.136684461 +0200
@@ -39,11 +39,12 @@
begin
# Get the Fog server object for given machine
server = env[:aws_compute].servers.get(env[:machine].id)
+ servername = "#{server.tags["Name"]}".chomp!
env[:ui].info(I18n.t("vagrant_aws.packaging_instance", :instance_id => server.id))
-
+
# Make the request to AWS to create an AMI from machine's instance
- ami_response = server.service.create_image server.id, "#{server.tags["Name"]} Package - #{Time.now.strftime("%Y%m%d-%H%M%S")}", ""
+ ami_response = server.service.create_image server.id, "#{servername}-Package-#{Time.now.strftime("%Y%m%d-%H%M%S")}", ""
# Find ami id
@ami_id = ami_response.data[:body]["imageId"]
Hey @hseipp,
Thanks a lot for looking into it! This is helpful!
Would opening PR in vagrant-aws help? It does not seem to be very active though.
Hey @morazow indeed, getting a vagrant-aws PR accepted would be the ideal way, but looking at the PR queue there I have no hopes that such will happen soon. For now, I'm adding the above workaround to the README.
Hey @hseipp,
Yes, that is fine. I am going to close the ticket.
Best
Currently running vagrant package step for AWS setup fails with following exception: