# Correct way to target default inventory with playbook written for localhost

**URL:** <https://forum.ansible.com/t/correct-way-to-target-default-inventory-with-playbook-written-for-localhost/38304>\
**Category:** Ansible Project\
**Created:** [August 5, 2023, 3:13pm UTC](https://forum.ansible.com/t/correct-way-to-target-default-inventory-with-playbook-written-for-localhost/38304 "2023-08-05T15:13:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RedNek\_Tek](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@RedNek\_Tek](https://forum.ansible.com/u/RedNek_Tek)\
**Post date:** [August 5, 2023, 3:13pm UTC](https://forum.ansible.com/t/correct-way-to-target-default-inventory-with-playbook-written-for-localhost/38304/1 "2023-08-05T15:13:26Z")

</div>

In my journey of learning ansible, I come across playbooks written to target localhost - and I am trying to figure out how to run such playbooks against the inventory file /etc/ansible/hosts.

One example here: [https://github.com/ReinerNippes/nextcloud/tree/nextcloud-reloaded](https://github.com/ReinerNippes/nextcloud/tree/nextcloud-reloaded)

I have tried changing the host in the host groups defined in the inventory file to my target host like:

```auto
ansible_host=192.168.50.130 # my target test node

```

This gives the error:  
fatal: [ansible\_host=192.168.50.130]: FAILED! =\>  
msg: ‘’‘ansible\_pkg\_mgr’’ is undefined. ‘‘ansible\_pkg\_mgr’’ is undefined’

If I try to run it against my inventory with the -i switch, I get:  
[WARNING]: Could not match supplied host pattern, ignoring: nc

Anyone know the correct way to target the default inventory file? Or at least define the target host so it doesn’t run on my ansible node? The example playbook above runs fine, as long as I run it from within the target node. But would like to run them remotely against test containers. I usually just write small plays, so I am quite green with playbooks with many roles.  
Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 7, 2023, 2:49pm UTC](https://forum.ansible.com/t/correct-way-to-target-default-inventory-with-playbook-written-for-localhost/38304/2 "2023-08-07T14:49:30Z")

</div>

Try updating the play to `hosts: all` or change 'all' for the group of  
your inventory you want to target. 'localhost' is special so just  
changing `ansible_host` is not enough.  
[https://docs.ansible.com/ansible/latest/inventory/implicit\_localhost.html](https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html)
