host_vars和group_vars没有得到加载
问题描述:
我有下面的文件夹结构,这似乎使它建立和加载的角色,但组和主机变量没有被加载。怎么来的?host_vars和group_vars没有得到加载
的/ etc/ansible/
- hosts
- requirements.yml
- group_vars/
- app/
- postgres.yml
- host_vars/
- app1/
- postgres.yml
- roles
/文件/ ansible/
- playbook.yml
- vagrant
主机文件
# Application servers
[app]
192.168.60.6
# Group multi
[multi:children]
app
#variables applied to all servers
[multi:vars]
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/insecure_private_key
**流浪汉**
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Genral Vagrant VM Configuration.
config.vm.box = "geerlingguy/centos7"
config.ssh.insert_key = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider :virtualbox do |v|
v.memory = 256
v.linked_clone = true
end
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
end
# Application server 1
config.vm.define "app1" do |app|
app.vm.hostname = "orc-app1.dev"
app.vm.network :private_network, ip: "192.168.60.6"
end
end
答
流浪者默认使用自己的自动生成的库存文件.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
。
有在流浪的选项ansible.inventory_path
指向以外的清单文件/目录下自动生成一个,但你不能用它来指向Vagrantfile
的/etc/ansible/hosts
,让流浪者完全不知道它。同样,它不在/etc/ansible
中寻找host_vars
和group_vars
。
在另一方面,以角色的路径不被清单文件覆盖,使流浪使用它自己的一个不影响路径角色的事实。
它们默认从/etc/ansible/roles
(或Ansible用作其默认目录,例如macOS上的/usr/local/etc/ansible/roles
)加载。
所以我需要将'host_vars'和'group_vars'复制到playbook.yml文件夹中?以及我如何指向'/ etc/ansible/hosts' in vagrant文件? –
我不知道你需要什么,因为我不知道你想要什么。乍一看,为Vagrant项目使用全局清单文件是没有意义的,但也许你有自己的理由。我不确定第二个问题,我在答案中给出了设置的名称 - 使用它的问题是什么? – techraf
即使你像现在一样拷贝'group_vars',Vagrant也不会知道'app'是什么。它将从'host_vars'获取'app1',因为你在'Vagrantfile'中定义了'app1',它会反映在自动生成的库存中,而不是'app'。 – techraf