ansible - ansible playbook and hostvar connection
问题描述
I have inventory.ini file that is something like that and no host listed as host values can be updated as per the need.
[dev-dbservers]
---
---
[prod-dbservers]
to accommodate based on the environment. I want to add accounts differently. In my playbook, how can I use to point to the dev-dbservers
, or prod-dbservers
so it executes as needed per environment
解决方案
您可以在剧本中使用 var inhosts
参数,并且可以extra-vars
在执行剧本时使用,如下所示
ansible-playbook test.yml -i inventory.ini -e "env=prod-dbservers"
并编写您的剧本如下
---
- name: Testing
hosts: "{{ env }}"
become: yes
tasks:
- debug:
msg: "{{ ansible_hostname }}"
推荐阅读
- java - 使用特定元素的索引从另一个列表中获取项目(lambda 表示法)
- javascript - 使用javascript按类型和字段获取元素?
- css - 具有 sass 和控制图像溢出的响应式弹性框
- python - 如何正确格式化python代码结构?
- sql - PostgreSQL 错误:列“MANAGER”不存在
- python - 基本 Python 数据验证
- ios - 添加带有点击手势的图钉时,我的图钉会显示在其他地方。
- javascript - 如何使用 Javascript 使 Django 表单字段消失?
- java - Spark结构化流状态管理
- javascript - 使用 XML 解析时显示未定义的文档元素