petrel919 发表于 2015-9-16 08:57:32

ansible使用2

  默认位置
  

/etc/ansible/hosts  

  标准
  

mail.example.com  

  

  
foo.example.com
  
bar.example.com
  

  

  
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端口
  

  配置大量主机
  

  
www.example.com
  

  

  
db-.example.com
  

  指派连接用户和类型
  

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

  主机变量
  

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

  主机组变量
  

  
host1
  
host2
  

  

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

  主机组嵌套
  

  
host1
  
host2
  

  

  
host2
  
host3
  

  

  
atlanta
  
raleigh
  

  

  
some_server=foo.southeast.example.com
  
halon_system_timeout=30
  
self_destruct_countdown=60
  
escape_pods=2
  

  

  
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
页: [1]
查看完整版本: ansible使用2