• 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

  • 相关阅读:
    给X轴添加滚动条,放大X轴Y轴
    win7下发布网站
    asp.net播放声音
    用Flash方式动态生成图表
    debian programming guid
    php 自动跳转的3种方法
    用expect实现su c功能,身份切换
    11 Top Opensource Resources for Cloud Computing
    转:Linux系统下Shell命令行快捷键实用技巧
    sed 替换
  • 原文地址:https://www.cnblogs.com/liujitao79/p/4195143.html
Copyright © 2020-2023  润新知