On 08/05/2013 16:20, Gilles Cornu wrote:
> Salut Michel,
>
> Thanks for your feedbacks. I'm not sure to understand well your question:
>
>
> The other things that's missing I think it the ability to tell ansible
> the host name to use. I didn't really check but it seems ansible
> provisionner will use whatever IP it finds in the Vagrant config, or
> 127.0.0.1 if none.
>
>
> Vagrant uses argument --inventory-file with "ansible.inventory_file".
> You should check there...
Yes sorry, I wasn't very clear or awake :)
What I'm looking for is to use hostnames in inventory file without
touching /etc/hosts or adding ansible_ssh_host in the inventory.
For instance (example trimmed down) :
```
Vagrant.configure("2") do |config|
config.vm.define :webapp do |webapp|
webapp.vm.hostname = "webapp.local"
webapp.vm.network :private_network, ip: "192.168.123.2"
end
config.vm.provision :ansible do |ansible|
ansible.inventory_file = "vagrant/hosts"
end
end
```
with the following vagrant/hosts :
```
webapp.local
```
AFAIK, this can't be done unless inventory is :
```
webapp.local ansible_ssh_host=192.168.123.2
```
which leads to repetition (changing the IP or networking style involves
changing the inventory file).
It could be nice if hostname defined in webapp.vm.hostname to be mapped
automatically to host IP.
In previous vagrant versions, vagrant-hostmaster could do this but it's
not compatible with newer vagrant versions.
But there is an issue opened, and things are looking good and I don't
think it worth it to do something on the provisionner side (at first
sight it would be quite hairy to do).
However, the same apply to ansible_ssh_port if port 22 if forwarded in
the configuration.
May be an option to generate an inventory file with the proper
hostnames, ansible_ssh_host, ansible_ssh_port could be nice and would
solve all this for simple setups.
> This make me think on following: There is no "control" by Vagrant to run
> ansible-playbook against VMs configured in Vagrantfile! It could be nice
> to add some sanity check: Ideally, Vagrant should parse
> ansible.inventory_file, filter by ansible.limit and check if it maps
> with Vagrantfile host(s).
This is probably an ansible provisionner's responsability more than a
Vagrant one no ?
May be checking that the output of `ansible-playbook --list-hosts
--limit "#{config.limit}"` and checking that union with Vagrantfile
host(s) isn't nil could be enough ?