Ansible:host_variables 分组在一个文件中 [英] Ansible: host_variables grouping in one file
问题描述
我在每个服务器(主机)上都有一个具有不同值的键,如何将所有这些值保存在一个文件中,以便在执行我的剧本时从该文件中读取.
I have a key with different value on each server(host), how can I save all those values in a single file, so that when my playbook is executed it reads from that file.
来自 Ansible 文档:我在 host_vars/hostname 下发现我必须为每个服务器创建一个文件并添加变量.如果我有 100 台服务器会很麻烦
From Ansible documentation: I found under host_vars/hostname I have to create a file for each server and add the variable. It would be cumbersome if I have like 100 servers
推荐答案
您可以在清单文件中按主机设置变量,如下所示:https://docs.ansible.com/ansible/intro_inventory.html#host-variables
You can set variables by host in your inventory file like this: https://docs.ansible.com/ansible/intro_inventory.html#host-variables
Groups 和 group_vars 是另一种可能符合您要求的解决方案.
Groups and group_vars are another solution that may be fit your requirements.
这篇关于Ansible:host_variables 分组在一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!