Open kindlehl opened 4 years ago
@kindlehl, this is exactly the problem I bumped into as well. Your post gave me the bit I needed to fix my issue.
This doesn't work (why not!?):
config.vm.hostname = "server2"
config.vm.provision "ansible" do |ansible|
ansible.groups = {
"servers" => ["server1","server2"]
}
ansible.playbook = "ansible/site.yml"
end
The generate inventory file looks like this:
# Generated by Vagrant
default ansible_host=127.0.0.1 ansible_port=2200 ansible_user='ansible' ansible_ssh_private_key_file='........'
[servers]
Why doesn't it just copy the groups in and use the hostname??
Even with vm.define the create inventory file will just contain the 'defined' name and not both mentioned servers...
I would've thought that this should be made clear in the documentation...
I was trying to run a multi-machine environment with two centos boxes. I wanted to test the firewall configuration on 'mono' by hitting it from 'testing'. The documentation wasn't clear on how inventory is generated, so I assumed that it was based on the hostname set in the Vagrantfile, which would make sense. to me It took me a while to figure out that the hostname is set based on the argument given to
config.vm.define
, since the Vagrantfile had worked before I added a second VM which forced me to specify the name argument for the VMs.I think it'd make more sense to base the inventory hostnames on the hostname variable set, if is set; then default to the name of the VM given. Let me know what you think.
Here is my Vagrantfile