将EC2实例公共IP放入Ansible主机文件中

问题描述 投票:0回答:2

嘿,我是Ansible的新手并且正在为项目工作,其中一个步骤是将我们的rhel7实例公共IP地址输入到Ansible主机文件中。我们没有得到任何其他指令,我想确保我这样做是正确的(我的主机文件的第11行),任何反馈将不胜感激。主机文件

# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.
3.82.200.205
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

##[webservers]

## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com
ansible
2个回答
0
投票

要添加Vladimir的答案,在AWS中创建的服务器通常带有弹性IP,并且可以在重新启动服务器后进行更改

因此,当您的系统变得更大更复杂时,您需要使其成为动态库存,请参阅本文中的示例:https://medium.com/happy5/aws-dynamic-inventory-and-ansible-thank-god-i-can-sleep-more-4d2aeadbc6f。这种方法适用于我,我用它来管理50多个带有动态IP的AWS EC2实例

看起来这里有AWS插件:https://docs.ansible.com/ansible/latest/plugins/inventory/aws_ec2.html,我还没试过这个解决方案,但它可能有一些优势,因为这是来自Ansible官方文档


0
投票

是。这是正确的。这是Working with Inventory的链接(用于记录)。

© www.soinside.com 2019 - 2024. All rights reserved.