diff --git a/lib/vagrant/util/guest_hosts.rb b/lib/vagrant/util/guest_hosts.rb index c0c16c098..b6855002e 100644 --- a/lib/vagrant/util/guest_hosts.rb +++ b/lib/vagrant/util/guest_hosts.rb @@ -17,7 +17,7 @@ module Vagrant basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') grep -w '#{name}' /etc/hosts || { - for i in {1..#{loop_bound}}; do + for i in #{[*1..loop_bound].join(' ')}; do grep -w "127.0.${i}.1" /etc/hosts || { echo "127.0.${i}.1 #{name} #{basename}" >> /etc/hosts break diff --git a/test/unit/vagrant/util/guest_hosts_test.rb b/test/unit/vagrant/util/guest_hosts_test.rb index bc48dc81f..86be31117 100644 --- a/test/unit/vagrant/util/guest_hosts_test.rb +++ b/test/unit/vagrant/util/guest_hosts_test.rb @@ -20,8 +20,8 @@ describe "Vagrant::Util::GuestHosts" do end it "can add hostname to loopback interface" do - subject.add_hostname_to_loopback_interface(comm, "test.end", 40) - expect(comm.received_commands[0]).to match(/for i in {1..40}; do/) + subject.add_hostname_to_loopback_interface(comm, "test.end", 4) + expect(comm.received_commands[0]).to match(/for i in 1 2 3 4; do/) expect(comm.received_commands[0]).to match(/echo \"127.0.\${i}.1 test.end test\" >> \/etc\/hosts/) end end @@ -35,8 +35,8 @@ describe "Vagrant::Util::GuestHosts" do end it "can add hostname to loopback interface" do - subject.add_hostname_to_loopback_interface(comm, "test.end", 40) - expect(comm.received_commands[0]).to match(/for i in {1..40}; do/) + subject.add_hostname_to_loopback_interface(comm, "test.end", 4) + expect(comm.received_commands[0]).to match(/for i in 1 2 3 4; do/) expect(comm.received_commands[0]).to match(/echo \"127.0.\${i}.1 test.end test\" >> \/etc\/hosts/) end end