# opposite of --limit (to exclude hosts)

**URL:** <https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937>\
**Category:** Ansible Project\
**Created:** [April 27, 2023, 7:51am UTC](https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937 "2023-04-27T07:51:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [April 27, 2023, 7:51am UTC](https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937/1 "2023-04-27T07:51:27Z")

</div>

ist there anything like a negation of --limit (to not execute a playbook on the named remotes) ?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [April 27, 2023, 8:59am UTC](https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937/2 "2023-04-27T08:59:54Z")

</div>

Hi,

> ist there anything like a negation of --limit (to not execute a  
> playbook on the named remotes) ?

you can use `!` for that in the `--limit` expression:

&nbsp;&nbsp;`ansible-playbook --limit 'servers,!specific_server,!specific_group ...`

That will use all servers from the group `servers`, except  
`specific_server`, and all servers in `specific_group`.

(You can also leave away `servers` to run the playbook on all hosts it  
wants to run on, except the ones excluded with `!`.)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [April 27, 2023, 1:45pm UTC](https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937/3 "2023-04-27T13:45:22Z")

</div>

thanks

I can make it work with inline --limit '!specific\_server' but could not figure out the right syntax for adresseing a list

&nbsp;&nbsp;&nbsp;&nbsp;'ansible all --limit "@limit.file" -m ping' is waht I am doing

tried several ways for adding the '!' to the above but could not make it work yet

---

<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:** [April 27, 2023, 2:16pm UTC](https://forum.ansible.com/t/opposite-of-limit-to-exclude-hosts/37937/4 "2023-04-27T14:16:30Z")

</div>

limit will ONLY create a subset of hosts, it will never ADD to the  
list of hosts to consider. What you need is to expand your inventory,  
which you can do with additional -i entries:

ansible-playbook myplay,yml -i hosts.yml -i 10.0.0.2,10.0.0.3,

This adds 2 hosts to the inventory, but only to the 'all' and  
'ungrouped' groups, you would need a custom inventory plugin to add  
them to specific groups.
