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

时间:2019-03-21 00:40:25

标签: ansible

嘿,我是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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

要附加弗拉基米尔的答案,在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官方文档