# Is possible to write 1 inv file with severl groups and run ansible-playbook for 1 group?

**URL:** <https://forum.ansible.com/t/is-possible-to-write-1-inv-file-with-severl-groups-and-run-ansible-playbook-for-1-group/40594>\
**Category:** Get Help\
**Created:** [February 24, 2025, 5:13pm UTC](https://forum.ansible.com/t/is-possible-to-write-1-inv-file-with-severl-groups-and-run-ansible-playbook-for-1-group/40594 "2025-02-24T17:13:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliassal](https://avatars.discourse-cdn.com/v4/letter/e/43a26b/32.png) [@eliassal](https://forum.ansible.com/u/eliassal)\
**Post date:** [February 24, 2025, 5:13pm UTC](https://forum.ansible.com/t/is-possible-to-write-1-inv-file-with-severl-groups-and-run-ansible-playbook-for-1-group/40594/1 "2025-02-24T17:13:31Z")

</div>

Hi, I have an inventory file as follows and would like to know if it is possible to run the playbook but for 1 group in the inv file

```auto
web1 ansible_ssh_host=192.168.33.20 ansible_ssh_user=vagrant ansible_ssh_pass=vagrant username=ansible_user 
db1 ansible_ssh_host=192.168.33.30 

[webservers]
web1

[dbservers]
db1

[datacenter:children]
webservers
dbservers

[datacenter:vars]
ansible_ssh_user=vagrant
ansible_ssh_pass=vagrant

```

When I run  
`ansible-playbook -i inv webserves myplaybook.yml`

I get an error indicating that webservers is not a playbook.

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/1/1a4af62e58519867323c6cd25acae5ee1ba239eb.png)

I tried

```auto
ansible-playbook webserves -i inv webserves myplaybook.yml
ansible webserves -i inv webserves myplaybook.yml

```

but did not help  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![kristianheljas](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/kristianheljas/32/7702_2.png) [@kristianheljas](https://forum.ansible.com/u/kristianheljas)\
**Post date:** [February 24, 2025, 5:21pm UTC](https://forum.ansible.com/t/is-possible-to-write-1-inv-file-with-severl-groups-and-run-ansible-playbook-for-1-group/40594/2 "2025-02-24T17:21:37Z")

</div>

You can specify targets in the playbook via `hosts` field if you want to do it permanently.

```yaml
- hosts: webservers
  tasks:
    - ...

```

If you want to limit it via cli use [–limit](https://docs.ansible.com/ansible/latest/cli/ansible-playbook.html#cmdoption-ansible-playbook-l) option, like so:

```auto
ansible-playbook -i inv --limit webservers myplaybook.yml

```

See [Patterns: targeting hosts and groups — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html#patterns-and-ad-hoc-commands) for more info
