jaugustin / vagrant-ansible-local

Vagrant plugin that provision your VM with ansible playbooks directly from the guest VM
MIT License
65 stars 5 forks source link

provision fails with "ERROR: provided hosts list is empty" #1

Open Sgoettschkes opened 10 years ago

Sgoettschkes commented 10 years ago

I am trying to run the plugin with my debian 7 base box which has ansible installed but not any specific host file in place. I am guessing the plugin wants to use the default hosts file.

Up until now, I am running the local ansible with the command ansible-playbook -i 'localhost ansible_connection=local,' /path/to/playbook.yml which bypasses the hosts file completly.

I did some digging and came across :raw_arguments, which can be used to bypass the hosts file as well: :raw_arguments => "-i 'localhost ansible_connection=local,'"

As the config.rb is saying, this is a joker argument and I don't really feel good using it. I'd like to change it for the better. As far as I'm concerned, there should be no problem changing the default hosts file to something build in?

If this is in your interest as well, I'd see if I can find some time writing a pull request. I'm not really good at ruby or vagrant plugins, but I could give it a try I guess.

jaugustin commented 10 years ago

I would be happy to review and accept your pr

therealmarv commented 10 years ago

If you are using the plugin as described in the readme config.vm.provision :ansibleLocal, :playbook => "provisioning/playbook.yml" there is no host file and the playbook.yml host needs to point to 127.0.0.1 like hosts: 127.0.0.1

But I also feel better when there is a hosts variable. This is how I use hosts currently (also with the raw_arguments): https://github.com/PyBossa/pybossa/blob/39ca8649a358bda852efae390acd5b0b3bbe96cc/Vagrantfile#L33

BTW: I do not know if it is wise to use Ansible directly on the VM... the plugin's task is to automate ansible usage locally. Something like vagrant provision from the host seems better.

Maybe I will make a PR soon ;)

Sgoettschkes commented 10 years ago

@therealmarv I have hosts: localhost in my playbook.yml, maybe that's the problem. Will try! If this solves my problem, I think putting it in the readme would be enough (at least for me?).

Regarding running ansible on the host: Vagrant has this built-in! I don't like this because it means there is another dependency on the host which makes the vagrant box harder to boot.

EDIT: Tried putting hosts: 127.0.0.1 but ansible is still complaining about an empty hosts file!

therealmarv commented 10 years ago

From what I understand you are using this plugin maybe wrong. This plugin configures the usage of ansible controlled from the host Vagrant and it will run on the VM with a --connection=local https://github.com/jaugustin/vagrant-ansible-local/blob/60ea51f8e6cda887a37389e5aef21639a95d32dc/lib/vagrant-ansible-local/provisioner.rb#L21 This is also described in the Ansible docs: http://docs.ansible.com/playbooks_delegation.html#local-playbooks There should be no need at any point to run ansible by hand on the VM with the command ansible-playbook and if you want to do so do it the same as this plug in with --connection=local.

I've got this plugin without issues running as described in the README on https://github.com/PyBossa/pybossa/tree/c5d429561c4b0f5aa74fb9a32f7caa541cee149e (see Vagrantfile and Provisioning directory).

Sgoettschkes commented 10 years ago

@therealmarv No, I use it pretty much the same as you do. I don't want to ssh into the vm and run ansible, I just want it run when I do vagrant provision.

My playbooks.yml file:

- hosts: 127.0.0.1
  connection: local
  sudo: yes
  tasks:
  - include: tasks/main.yml
  handlers:
  - include: handlers/main.yml

Running vagrant provision produces the following (cut down for readability) output:

ERROR: provided hosts list is empty
ansible-playbook /tmp/vagrant-ansible-local/playbook.yml --connection=local

I looked up my /etc/ansible/hosts file and it's the default one shipped with ansible 1.7.2 on debian jessie. There are only comments in there, so it's really empty.

therealmarv commented 10 years ago

The problem is not this plug in. The problem is that your Ansible is too old. I can reproduce your problem even with Ubuntu 14.04. Try either to install newest Ansible as described here http://docs.ansible.com/intro_installation.html before using Ansible-local or you can try out this option https://github.com/mitchellh/vagrant/issues/3096#issuecomment-37237086 This will fix your problem. I also install newest Ansible with PPAs in Ubuntu for this reason. Ansible is not that old and there can be bugs like this in old OS packages.

Sgoettschkes commented 10 years ago

I am running ansible 1.7.2 which is 2 month old. Given the current version of this plugin is a year old, I am not sure if this could be the reason? I also think there might be ways to improve this plugin so using a 2-month old version doesn't throw errors.

As said, there are ways to prevent this (see my initial issue description) and I think those could be incorporated into the plugin so others don't stumble upon them.

therealmarv commented 10 years ago

This issue was introduced with Ansible 1.5 on March 2014 https://github.com/mitchellh/vagrant/issues/3096 . So before Ansible 1.5 this plugin worked and now with the newest Ansible it also works. Seems not many people were using vagrant-ansible-local or found the way to avoid this bug. A PR which describes a workaround like ansible.limit = 'all' in the readme of this plugin would be helpful ;)

Sgoettschkes commented 10 years ago

I get it now. Adding it to the readme might work. After https://github.com/jaugustin/vagrant-ansible-local/pull/2 is merged, one can simply add "localhost," as inventory_path to fix this. Using the limit option didn't help me.

EDIT: I just tried, adding anything to my /etc/ansible/hosts file solves this as well. It doesn't matter if I define localhost in there or just some random IP.

rosscdh commented 8 years ago

Am encountering this same error with

ansible --version
ansible 2.0.0.2
  config file =
  configured module search path = Default w/o overrides

running

ansible-playbook all -i hosts setup-ci.yml
ERROR! Missing target hosts