ansible使用2-inventory & dynamic inventory

默认位置

/etc/ansible/hosts

标准

mail.example.com

[webservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com
# 2个主机组webservers&dbservers,一个孤儿主机mail.example.com

非默认ssh端口

badwolf.example.com:5309

主机别名&ssh通道

jumper ansible_ssh_port=5555 ansible_ssh_host=192.168.1.50
# jumper是主机别名,连接192.168.1.50:5555端口

配置大量主机

[webservers]
www[01:50].example.com

[databases]
db-[a:f].example.com

指派连接用户和类型

[targets]
localhost              ansible_connection=local
other1.example.com     ansible_connection=ssh        ansible_ssh_user=mpdehaan
other2.example.com     ansible_connection=ssh        ansible_ssh_user=mdehaan

主机变量

[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909
# 变量http_port,maxRequestsPerChild用于playbook 

主机组变量

[atlanta]
host1
host2

[atlanta:vars]
ntp_server=ntp.atlanta.example.com
proxy=proxy.atlanta.example.com
# 关键字:var,变量ntp_server,proxy

主机组嵌套

[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
# 关键字:children

在文件存储主机及主机组变量

/etc/ansible/group_vars/raleigh
/etc/ansible/group_vars/webservers
/etc/ansible/host_vars/foosball
# 主机foosball,主机组raleigh & webservers

dynamic inventory
/etc/ansible/hosts是基于文本管理的数据,可以将inventory存储在数据库,使用http api进行交互。编写脚本将inventory数据json化。
http://docs.ansible.com/developing_inventory.html

你可能感兴趣的:(dynamic)