4

For some reason, ansible's ec2 hosts is missing instances. ec2-describe-instances returns the correct instances, but /etc/ansible/hosts does not:

[root@or-manage ec2-user]# ec2-describe-instances | grep seed
TAG     instance        i-ff0b2f36      Name    cass-uat-seed
[root@or-manage ec2-user]# /etc/ansible/hosts | grep seed
[root@or-manage ec2-user]#

You can see that ec2-describe-instances has the instance with the tag I'm looking for, but ansible hosts does not.

Why is that instance not in there for /etc/ansible/hosts?


Note: At first, I thought it was /etc/ansible/hosts using the wrong region, but I turned up the boto debug and it IS the correct region:

send: 'POST / HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 221\r\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\r\nHost: ec2.us-west-2.amazonaws.com


Update 1:

I've noticed that any instances without a public IP do not appear in the /etc/ansible/hosts list. Why would that be?

1 Answer 1

5

I had to tweak the following knobs (in /etc/ansible/ec2.ini):

# This is the normal destination variable to use. If you are running Ansible
# from outside EC2, then 'public_dns_name' makes the most sense. If you are
# running Ansible from within EC2, then perhaps you want to use the internal
# address, and should set this to 'private_dns_name'. The key of an EC2 tag
# may optionally be used; however the boto instance variables hold precedence
# in the event of a collision.
destination_variable = private_dns_name

# For server inside a VPC, using DNS names may not make sense. When an instance
# has 'subnet_id' set, this variable is used. If the subnet is public, setting
# this to 'ip_address' will return the public IP address. For instances in a
# private subnet, this should be set to 'private_ip_address', and Ansible must
# be run from within EC2. The key of an EC2 tag may optionally be used; however
# the boto instance variables hold precedence in the event of a collision.
vpc_destination_variable = private_ip_address
2
  • 2
    This really helped me. Thanks. I am guessing your Ansible management node is hosted in the same VPC that you are deploying to correct? It seems changing to this makes the ec2.py file return private IPs. Jan 28, 2016 at 9:16
  • 2
    If you make a change, don't forget to change the cache value "cache_max_age" or you will see the same results.
    – Joey V.
    Sep 23, 2016 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.