Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为Ansible'中的所有主机全局设置参数/变量;谁的剧本?_Ansible_Automated Deploy - Fatal编程技术网

如何为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,得到我想要的!