Ansible EC2 主机脚本缺少实例

mty*_*son 4 amazon-ec2 amazon-web-services ansible

出于某种原因,ansible 的 ec2 主机缺少实例。ec2-describe-instances 返回正确的实例,但 /etc/ansible/hosts 没有:

[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]#
Run Code Online (Sandbox Code Playgroud)

您可以看到 ec2-describe-instances 具有带有我正在寻找的标签的实例,但 ansible hosts 没有。

为什么那个实例不在 /etc/ansible/hosts 中?


注意:起初,我以为它/etc/ansible/hosts使用了错误的区域,但我打开了 boto 调试,它正确的区域:

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


更新 1:

我注意到没有公共 IP 的任何实例都不会出现在 /etc/ansible/hosts 列表中。为什么会这样?

mty*_*son 5

我不得不调整以下旋钮(在/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
Run Code Online (Sandbox Code Playgroud)

  • 这真的帮助了我。谢谢。我猜您的 Ansible 管理节点托管在您要正确部署的同一个 VPC 中?似乎更改为这会使 ec2.py 文件返回私有 IP。 (2认同)
  • 如果您进行更改,请不要忘记更改缓存值“cache_max_age”,否则您将看到相同的结果。 (2认同)