如何为Ansible'中的所有主机全局设置参数/变量;谁的剧本?
现在我有一个剧本看起来像如何为Ansible'中的所有主机全局设置参数/变量;谁的剧本?,ansible,automated-deploy,Ansible,Automated Deploy,现在我有一个剧本看起来像 - hosts: hws gather_facts: no vars_files: - variables.yml roles: - role: hypervisor - hosts: vms gather_facts: no vars_files: - variables.yml roles: - role: web-server 而且它看起来很丑。如何设置 gather_facts: no vars
- hosts: hws
gather_facts: no
vars_files:
- variables.yml
roles:
- role: hypervisor
- hosts: vms
gather_facts: no
vars_files:
- variables.yml
roles:
- role: web-server
而且它看起来很丑。如何设置
gather_facts: no
vars_files:
- variables.yml
对于整个文件中的每个主机,您可以使用ansible目录布局根据主机组或主机对变量进行分组
ansible.cfg
hosts
group_vars/
hws.yml #variables for hws hosts
vms.yml #variables for vms hosts
all #here you can put variables commont to both hws + vms
roles/
hypervisor
web-server
playbook.yml
这样,您就不需要在剧本中包含变量文件
您还可以在此处阅读有关ansible目录结构的更多信息:
关于变量优先级:
祝你好运 非常感谢你的回答!我将我的公共vars文件移动到group_vars/all,并将string
collection=explicit
添加到ansible.cfg,得到我想要的!