ansible - 在组变量中设置 ansible_host
问题描述
这可能是一个愚蠢的想法,但我的 ansible 脚本有两个相同的游乐场。
我想创建一个包含两个组的清单并通过组从主机中选择 ip 这可能吗?我需要它是因为前端和后端在两个组中都需要相同的 host_vars,但它们是不同的服务器。
主机变量:
frontend.yml(在 host_vars 中):
frontent_property=look good
后端 .yml(在 host_vars 中):
backend_property=handle requests
组变量:
integration.yml(在 group_vars 中):
integration_property=have fun
production.yml(在 group_vars 中):
production_property=do business
存货:
frontend
backend
[integration]
frontend ansible_host=10.0.0.5
backend ansible_host=10.0.0.6
[production]
frontend ansible_host=10.1.0.5
backend ansible_host=10.1.0.6
剧本:
- hosts: integration
gather_facts: false
tasks:
- debug:
msg: "{{ ansible_host }}"
- hosts: production
gather_facts: false
tasks:
- debug:
msg: "{{ ansible_host }}"
这不起作用(两者都针对集成 ips 运行)-是否有另一种解决方案来解决这个问题?
我找到了解决方案,但现在我失去了 host_vars :
group_vars:frontend.yml(在 group_vars 中):
frontent_property=look good
backend.yml(在 group_vars 中):
backend_property=handle requests
integration.yml(在 group_vars 中):
some_property=have fun
production.yml(在 group_vars 中):
some_property=do business
存货:
10.0.0.5
10.0.0.6
10.1.0.5
10.1.0.6
[frontend]
10.0.0.5
10.1.0.5
[backend]
10.0.0.6
10.1.0.6
[integration]
10.0.0.6
10.0.0.5
[production]
10.1.0.5
10.1.0.6
但更可能是我犯了一个错误,因为我没有使用 :children 说明符(Group in Group)所以我不认为 [backend] 中的组值可以从范围 [integration]/production 或我错了吗?
解决方案
这是正确的库存
10.0.0.5
10.0.0.6
10.1.0.5
10.1.0.6
[integration]
10.0.0.5 my_hostname=frontend
10.0.0.6 my_hostname=backend
[production]
10.1.0.5 my_hostname=frontend
10.1.0.6 my_hostname=backend
推荐阅读
- sql - 子查询上的聚合/求和函数
- javascript - 动态按钮(由 ajax 生成)不可点击
- javascript - 删除出现在 textarea 中默认值字符串之前/之后的逗号
- python - 检查(使用 Firefox)显示加密的类名
- git - 如何在 Github 上将本地分支更新为远程主控?
- reactjs - “Window & typeof globalThis”类型上不存在属性“MktoForms2”
- amazon-web-services - Redshift Scheduler 无法创建计划
- python - ¿ 如何在 Python 中从多个文件夹中读取多个文件
- angular - Ag-Grid 编辑单元格颜色(如果已编辑)
- reactjs - npx create-react-app my-app yield result 'create-react-app' 无法识别