Unable to parse /etc/ansible/hosts as an inventory source

15,220 views
Skip to first unread message

Rob Christian

unread,
Jun 21, 2018, 4:13:09 PM6/21/18
to Ansible Project
How can I have my Ansible project use only the local `/inventories` directory? I am getting this output and I get the impression that Ansible is not finding my inventories.

 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source


 [WARNING]: No inventory was parsed, only implicit localhost is available


 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


 [WARNING]: Could not match supplied host pattern, ignoring: kube-master


I'm new to Ansible and I'm confused that Ansible looks outside the project directory by default.

I see that other people who have reported this issue also installed with Homebrew, as I have, but I don't yet see a clear solution.

The Ansible project was cloned from here: https://github.com/sebiwi/kubernetes-coreos

Rob Christian

unread,
Jun 21, 2018, 4:34:54 PM6/21/18
to Ansible Project
Ah ha, looks like the command needs to begin with `ansible -i inventories/vagrant.ini` for this project. Other examples I was following use simply `-i inventory`, so it wasn't clear to me that I need to reference this vagrant.ini file. I don't understand why this project is setup this way. I would expect Ansible to default first any local inventory file, but today is the first day I'm using Ansible.

I'm trying to follow the project author's guide but I think he assumes readers are already familiar with Ansible.

Marcos Alano

unread,
Jun 21, 2018, 4:36:47 PM6/21/18
to ansible...@googlegroups.com
You could define the option "inventory" inside ansible.cfg. You can define a file or a directory.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/314a095c-87da-4646-9b0b-ec375580870b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcos H. Alano
Linux System Administrator
marcos...@gmail.com

Matt Martz

unread,
Jun 21, 2018, 4:43:30 PM6/21/18
to ansible...@googlegroups.com
By default ansible ignores files with a .ini extension when using an inventory directory.  This is due to many dynamic inventory scripts using a .ini extension for their configuration files.


So when using `-i inventories/` that `vagrant.ini` is ignored, as opposed to explicitly listing that `vagrant.ini` as your inventory source.

Simply removing the `.ini` extension would allow the directory version to work.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/314a095c-87da-4646-9b0b-ec375580870b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

stifan kristi

unread,
Jun 21, 2018, 8:04:49 PM6/21/18
to Ansible Project
is file /etc/ansible/hosts exist? perhaps you should create it first
e.g.
sudo mkdir /etc/ansible/
sudo touch
/etc/ansible/hosts
sudo chmod
777 /etc/ansible/hosts
sudo echo
"localhost ansible_connection=local" >> /etc/ansible/hosts

best regards,
stifan

bng....@gmail.com

unread,
Jan 20, 2019, 12:56:23 PM1/20/19
to Ansible Project
also make sure that you are in the root directory while doing mkdir

James Cassell

unread,
Jan 20, 2019, 1:32:32 PM1/20/19
to Ansible List


On Sun, Jan 20, 2019, at 12:56 PM, bng....@gmail.com wrote:
> also make sure that you are in the root directory while doing mkdir
>
> On Friday, June 22, 2018 at 5:34:49 AM UTC+5:30, stifan kristi wrote:
> >
> > is file /etc/ansible/hosts exist? perhaps you should create it first
> > e.g.
> > sudo mkdir /etc/ansible/
> > sudo touch /etc/ansible/hosts
> > sudo chmod 777 /etc/ansible/hosts

Pretty sure that making the inventory executable will cause ansible to try to run it as a script then use the output as inventory.

V/r,
James Cassell
Reply all
Reply to author
Forward
0 new messages