ansible Inventory模板

一、INI

1、在ansible中的Inventory文件中有两种组:默认组和自定义组;默认组包含all和ungrouped,all组包含所有的主机,ungrouped包含没有自定义组的主机。一个主机一定属于all组,并且也属于ungrouped或者自定义组中其中一个。在INI中,ungrouped可以显示指定吗?
2、一个主机可以属于多个组。
3、主机后可以跟自定义变量,主机后的变量只属于该主机。
4、主机后可以设置ssh链接参数。
5、可以在配置文件中定义主机别名。
6、可以定义组级别的变量,即变量属于一个组内的所有主机。
7、父组(partent 组)与子组(child 组),父组是包含子组的。在INI中使用 :children 关键字来指定子组,组之间可以多层嵌套,即父组可以包含父组,再包含子组
8、父组中定义的变量可以对该父组的所有子组生效,即子组可以继承父组的变量,但是子组的变量并不会对父组生效,并且子组的变量等级要高于父组,即如果父组与子组有同一个变量,则子组的变量生效

# Default groups  这个主机属于默认ungrouped组,也属于all组
# 主机后跟自定义变量,
10.231.214.100 http_port=80 maxRequestsPerChild=808

# 以下主机属于all组和webservers组
# 主机后设置ssh链接参数
[webservers]
foo.example.com  ansible_port=2222 ansible_user=kafka
10.231.214.101

[dbservers]
one.example.com
two.example.com
10.231.214.102
foo.example.com
# 定义组级别的变量,如下所有变量属于dbservers组内的所有机器,语法如下,需要加上:vars
[dbservers:vars]
dbname=esbimon
dbuser=esbimon
dbpassword=lllll


[zookeeper]
# 定义主机别名
esb  ansible_host=10.231.214.30 ansible_port=5555 

[atlanta]
host1
10.231.22.100

[raleigh]
10.231.214.79
host3

# 父组southeast包含atlanta和raleigh 两个子组
[southeast:children]
atlanta
raleigh

# 父组southeast的变量对atlanta和raleigh子组生效
[southeast:vars]
some_server=foo.southeast.example.com
halon_system_timeout=30
self_destruct_countdown=60
escape_pods=2

# 父组包含其他父组
[usa:children]
southeast
northeast
southwest
northwest

二、YAML

1、在yaml格式中,ungrouped组要显示的定义出来
2、在yaml中使用 ==children:==代表子组
3、在yaml中使用 ==vars:==代表变量

ungrouped:                # ungrouped组要显示的定义出来
  hosts:
    mail.example.com:
atlanta:                  # 定义一个组
  hosts:
    10.231.214.100:       # 指定主机(ip,主机名)
      http_port: 80       # 指定主机范围内的变量
      maxRequestsPerChild: 808
    host2:
      http_port: 303
      maxRequestsPerChild: 909
kafka:                   # 定义一个组
  hosts:                 # 定义组内的主机列表
    10.231.214.101:
    host2:
    10.231.214.103:
  vars:                  # 定义组范围的变量
    ntp_server: ntp.atlanta.example.com
    proxy: proxy.atlanta.example.com
# 组与组之间的嵌套
usa:
  children:
    southeast:
      children:
        atlanta:
          hosts:
            host1:
            host2:
        raleigh:
          hosts:
            host2:
            host3:
      vars:
        some_server: foo.southeast.example.com
        halon_system_timeout: 30
        self_destruct_countdown: 60
        escape_pods: 2
    northeast:
    northwest:
    southwest:

与如下INI格式的相同

[atlanta]
host1
host2

[raleigh]
host2
host3

[southeast:children]
atlanta
raleigh

[southeast:vars]
some_server=foo.southeast.example.com
halon_system_timeout=30
self_destruct_countdown=60
escape_pods=2

[usa:children]
southeast
northeast
southwest
northwest

引用

behavioral inventory parameters

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值