为了账号安全,请及时绑定邮箱和手机立即绑定

Ansible Inventory - 管理主机的清单

标签:
架构

webp

默认存于 /etc/ansible/hosts 文件中,也可以通过 -i <PATH> 指定到文件。

主机和组

示例:INI 格式

all.example.com

other ansible_port=5555 ansible_host=192.0.2.50

[webservers]
web1.example.com
web2.example.com

[dbservers]
db1.example.com
db2.example.com
db3.example.com

[otherservers]
other.example.com:8080

示例:YAML 格式

all:  hosts:    all.example.com
    other:      ansible_port: 5555      ansible_host: 192.0.2.50
  children:    webservers:      hosts:        web1.example.com:        web2.example.com:    dbservers:      hosts:        db1.example.com:        db2.example.com:        db3.example.com:

主机变量

可供 playbooks 使用,示例:

[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909

组变量

示例:INI 格式

[atlanta]
host1
host2

[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com

示例:YAML 格式

atlanta:  hosts:    host1:    host2:  vars:    ntp_server: ntp.atlanta.example.com
    proxy: proxy.atlanta.example.com

群组和组变量

示例:INI 格式

[atlanta]
host1
host2

[raleigh]
host2
host3

[southeast:children]
atlanta
raleigh

[southeast:vars]
some_server=foo.southeast.example.com
halon_system_timeout=30

[usa:children]
southeast
northeast

示例:YAML 格式

all:  children:    usa:      children:        southeast:          children:            atlanta:              hosts:                host1:                host2:            raleigh:              hosts:                host2:                host3:          vars:            some_server: foo.southeast.example.com
            halon_system_timeout: 30       northeast:

如果需要存储列表或散列数据,建议将主机和组特定变量与 Inventory 文件分开。

关于群组的补充说明:

  • 任何属于子组的成员都自动成为父组的成员

  • 子组的变量将具有更高的优先级(覆盖父组的变量)

  • 组可以有多个父母和孩子,但不是循环关系

  • 主机也可以在多个组中,但只有一个主机实例,合并来自多个组的数据

默认组

有两个默认组:allungrouped

  • all 包含每个主机。

  • ungrouped 包含所有没有另一个组的主机。

即每个主机将永远属于至少2个组。



作者:Anoyi
链接:https://www.jianshu.com/p/3dfa1ae67c32


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消