涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  428 随笔 :: 0 文章 :: 19 评论 :: 22万 阅读

默认位置

/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

posted on   北京涛子  阅读(855)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示