亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
算法工程師
手記
粉絲
41
獲贊與收藏
160

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消