如何正确构建 Ansible 库存
我想构建一个 Ansible 库存,但又不想让它变得像意大利面条一样,而且我喜欢保持 DRY。 我查看了 Ansible 文档,但我不能查找以下信息:
我目前正在使用此格式来构建库存。
[dev-postgres]
a1-dev-01 ansible_host=vm-1.my.internal.domain.com
a1-dev-02 ansible_host=vm-2.my.internal.domain.com
[dev-ldap]
a1-dev-02 ansible_host=vm-2.my.internal.domain.com
a1-dev-03 ansible_host=vm-3.my.internal.domain.com
[dev:children]
dev-ldap
dev-postgres
[dev:vars]
env=dev
[jumphost]
a2-jump-01 ansible_host=vm-0.my.internal.domain.com
关于此设置,我有三个问题:
- 是否可以为每个 ansible_host 定义“vm-x”,并配置“.my.internal.domain.com”一次,并且每个主机都会将该值附加到其 ansible_host 值中?
- 是否可以为每个主机定义一次名称(例如a6-dev-01)+ ansible_host。然后可以在多个组下设置名称(例如a6-dev-01),而无需定义ansible_host?
- 组的名称可以有多个值吗?例如
[dev-postgres, another_value]
?
I want to build an Ansible inventory without making it spaghetti and I like to be DRY.
I took a look at the Ansible Docs, but I can't find the information for the following:
I am currently using this format to build an inventory.
[dev-postgres]
a1-dev-01 ansible_host=vm-1.my.internal.domain.com
a1-dev-02 ansible_host=vm-2.my.internal.domain.com
[dev-ldap]
a1-dev-02 ansible_host=vm-2.my.internal.domain.com
a1-dev-03 ansible_host=vm-3.my.internal.domain.com
[dev:children]
dev-ldap
dev-postgres
[dev:vars]
env=dev
[jumphost]
a2-jump-01 ansible_host=vm-0.my.internal.domain.com
I have three questions regarding this setup:
- Is it possible, for each ansible_host, define 'vm-x', and configure the '.my.internal.domain.com' once, and each host will have that value appended to their ansible_host value?
- Is it possible to define for each host the name(e.g. a6-dev-01) + ansible_host once. And then the name(e.g. a6-dev-01) could be set under multiple groups, without defining ansible_host?
- Is it possible for the name of the group to have multiple values? E.g.
[dev-postgres, another_value]
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用构建库存插件。请参见
示例
给出
下一个选项是将变量放入 group_vars 中。例如
给出
唯一的区别是表达式将根据需要进行计算。这意味着变量vm_x和vm_domain将成为优先级。例如,剧本
给出(删节)
Use constructed inventory plugin. See
For example
gives
The next option is putting the variables into the group_vars. For example
gives
The only difference is that the expressions will be evaluated on demand. This means that the variables vm_x and vm_domain will be subjects of the precedence. For example the playbook
gives (abridged)