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

**URL:** <https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [June 21, 2018, 8:13pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844 "2018-06-21T20:13:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob\_Christian](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Christian](https://forum.ansible.com/u/Rob_Christian)\
**Post date:** [June 21, 2018, 8:13pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/1 "2018-06-21T20:13:09Z")

</div>

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](https://github.com/sebiwi/kubernetes-coreos)

---

<div class="post-metadata">

**Author:** ![Rob\_Christian](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Christian](https://forum.ansible.com/u/Rob_Christian)\
**Post date:** [June 21, 2018, 8:34pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/2 "2018-06-21T20:34:54Z")

</div>

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.  
[https://blog.octo.com/en/how-does-it-work-kubernetes-episode-5-master-and-worker-at-last/#comment-632228](https://blog.octo.com/en/how-does-it-work-kubernetes-episode-5-master-and-worker-at-last/#comment-632228)

---

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [June 21, 2018, 8:36pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/3 "2018-06-21T20:36:24Z")

</div>

You could define the option “inventory” inside ansible.cfg. You can define a file or a directory.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [June 21, 2018, 8:42pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/4 "2018-06-21T20:42:40Z")

</div>

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.

This blacklist is defined by [https://docs.ansible.com/ansible/latest/reference\_appendices/config.html#inventory-ignore-exts](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inventory-ignore-exts)

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.

---

<div class="post-metadata">

**Author:** ![stifan\_kristi](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@stifan\_kristi](https://forum.ansible.com/u/stifan_kristi)\
**Post date:** [June 22, 2018, 12:04am UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/5 "2018-06-22T00:04:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bng.zero1](https://avatars.discourse-cdn.com/v4/letter/b/46a35a/32.png) [@bng.zero1](https://forum.ansible.com/u/bng.zero1)\
**Post date:** [January 20, 2019, 5:56pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/6 "2019-01-20T17:56:23Z")

</div>

also make sure that you are in the root directory while doing mkdir

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [January 20, 2019, 6:32pm UTC](https://forum.ansible.com/t/unable-to-parse-etc-ansible-hosts-as-an-inventory-source/27844/7 "2019-01-20T18:32:20Z")

</div>

> also make sure that you are in the root directory while doing mkdir
> 
> \>  
> \> 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
