Caching variable name in .each
mattchilds1 opened this issue · 1 comments
mattchilds1 commented
Hi, I have a problem when I am creating multiple AWS machines. Locally they look like:
When I look on Amazon they unfortunately all have the name 'node1-aws'. Looking at the --debug output, it seems that it is using 'With machine: node1-aws' for every node.
INFO machine: Initializing machine: node3-aws
...
INFO machine: New machine ID: nil
INFO command: With machine: node1-aws (#<VagrantPlugins::AWS::Provider:0x00000102869bd0 @machine=#<Vagrant::Machine: node1-aws (VagrantPlugins::AWS::Provider)>
My vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
boxes = [
{
:name => "node1-aws",
:playbook => "remote-bootstrap.yml",
:region => "eu-west-1",
:ami => "ami-3910c44e",
:instance_type => "t2.micro",
:ansible_inventory => "amazon-ec2-inventory"
},
{
:name => "node2-aws",
:playbook => "remote-bootstrap.yml",
:region => "eu-west-1",
:ami => "ami-3910c44e",
:instance_type => "t2.micro",
:ansible_inventory => "amazon-ec2-inventory"
},
{
:name => "node3-aws",
:playbook => "remote-bootstrap.yml",
:region => "eu-west-1",
:ami => "ami-3910c44e",
:instance_type => "t2.micro",
:ansible_inventory => "amazon-ec2-inventory"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "etailer/ubuntu-13.10"
boxes.each do |opts|
config.vm.define opts[:name] do |node|
config.vm.provider :aws do |aws, override|
override.ssh.private_key_path = "~/.ssh/id_rsa"
aws.access_key_id = "removed"
aws.secret_access_key = "removed"
aws.region = opts[:region]
aws.keypair_name = "id_rsa"
aws.ami = "ami-3910c44e"
aws.instance_type = opts[:instance_type]
aws.tags = {
'Name' => opts[:name]
}
#override.vm.box = "etailer/ubuntu-13.10"
end #end of AWS
node.vm.provision "ansible" do |ansible|
ansible.verbose = "v"
ansible.playbook = "../remote-bootstrap.yml"
ansible.inventory_path = "../amazon-ec2-inventory"
ansible.host_key_checking = "true"
ansible.limit = "all"
end # end of ansible for aws
end #end of node
end #end of loop
end #end of vagrantfile
Is there some way to stop this cacheing? or am I just doing something stupid? 👯
hrpatel commented
Did you ever figure this out? Seems I've just run into the same issue.
More specifically, I'm getting the same AMI and Tags for each instance:
...
# Read in the JSON configuration
test_boxes = JSON.parse(
File.read(
File.join(File.dirname(__FILE__), config_file)
),
symbolize_names: true
)
...
# Start Vagrant configuration
Vagrant.configure(VAGRANTFILE_API_VERSION) do |vagrant|
...
# Loop through each box we define in the JSON file
test_boxes.each_pair do |vm_name, box_attributes|
...
# Configure instance specific AWS variables
vagrant.vm.provider :aws do |aws, override|
aws.ami = box_attributes[:ami]
aws.tags = {
# FIXME: all instances get the name of the first instance
'Name' => [ENV['USER'], vm_name].join('-'),
'Vagrant' => true
}
...