# bypass the need for ansible hosts file

**URL:** <https://forum.ansible.com/t/bypass-the-need-for-ansible-hosts-file/12381>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [February 18, 2013, 12:49pm UTC](https://forum.ansible.com/t/bypass-the-need-for-ansible-hosts-file/12381 "2013-02-18T12:49:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 18, 2013, 12:49pm UTC](https://forum.ansible.com/t/bypass-the-need-for-ansible-hosts-file/12381/1 "2013-02-18T12:49:05Z")

</div>

Actually, there is a way. It may not be the way you want. If you  
want to ignore the host file, you can, like so.

ansible-playbook foo.yml -i "hostname1,hostname2"

The only catch is if there is only one hostname, so that it knows it  
is a list and not a filename, the "-i" argument must end in a comma:

ansible-playbook foo.yml -i "hostname1"

The reason we don't allow unknown hosts straight up as there isn't a  
good way to tell what's a group, what's a typo, and what is a  
hostname.

Thus we don't want to try to connect to a group as if it were a  
hostname if the groupname were mispelled. Ansible will actually  
warn when no hosts are matched in a play.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [February 18, 2013, 1:12pm UTC](https://forum.ansible.com/t/bypass-the-need-for-ansible-hosts-file/12381/2 "2013-02-18T13:12:24Z")

</div>

so basically, the OP can have its way by putting this in his .bashrc:

# Run ansible on custom hosts

ansibleh() {  
hosts=$1  
shift  
ansible -i ${hosts}, all $\*  
}

Serge

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 18, 2013, 1:22pm UTC](https://forum.ansible.com/t/bypass-the-need-for-ansible-hosts-file/12381/3 "2013-02-18T13:22:27Z")

</div>

It would look a little different for ansible-playbook, but yes.
