diff --git a/lib/aws/aws_helpers.rb b/lib/aws/aws_helpers.rb index 30b3266..2f94358 100644 --- a/lib/aws/aws_helpers.rb +++ b/lib/aws/aws_helpers.rb @@ -175,9 +175,7 @@ def ec2_instance_describe(inst) # @param public [Boolean] use public or private IP def ec2_instance_etc_hosts(i, public = true) ip = public ? i.public_ip_address : i.private_ip_address - public_dns = i.public_dns_name.to_s - private_dns = i.private_dns_name.to_s - "#{ip}\t\t#{public_dns}\t\t#{private_dns}\t\t{HOST}" # template for HOST in settings + "#{ip}\t#{i.public_dns_name}\t#{i.private_dns_name}\t{HOST}" # template for HOST in settings end # Content for ~/.ssh/config diff --git a/spec/aws/aws_helpers_spec.rb b/spec/aws/aws_helpers_spec.rb index 354ff58..84df1a3 100644 --- a/spec/aws/aws_helpers_spec.rb +++ b/spec/aws/aws_helpers_spec.rb @@ -206,14 +206,21 @@ it 'works' do expect(etc_hosts).to be_an String end - it 'starts with Public IP' do + it 'starts with Public IP (by default)' do expect(etc_hosts).to start_with inst.public_ip_address end + it 'starts with Private IP (when requested)' do + etc_hosts = aws_helpers.ec2_instance_etc_hosts(inst, false) + expect(etc_hosts).to start_with inst.private_ip_address + end it 'includes Public DNS' do - expect(etc_hosts).to include inst.public_dns_name + expect(etc_hosts).to include "\t#{inst.public_dns_name}" end it 'includes Private DNS' do - expect(etc_hosts).to include inst.private_dns_name + expect(etc_hosts).to include "\t#{inst.private_dns_name}" + end + it 'includes {HOST} template' do + expect(etc_hosts).to include "\t{HOST}" end end