opposite of --limit (to exclude hosts)

636 views
Skip to first unread message

dulh...@mailbox.org

unread,
Apr 27, 2023, 3:51:46 AM4/27/23
to ansible...@googlegroups.com
ist there anything like a negation of --limit (to not execute a playbook on the named remotes) ?

Felix Fontein

unread,
Apr 27, 2023, 5:00:14 AM4/27/23
to ansible...@googlegroups.com
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:

`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

dulh...@mailbox.org

unread,
Apr 27, 2023, 9:45:38 AM4/27/23
to ansible...@googlegroups.com
thanks

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

'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
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20230427105954.1e062727%40rovaniemi.

---
gunnar wagner | fichtestr. 1, 19386 lübz | fon: 0176 7808 9090

Brian Coca

unread,
Apr 27, 2023, 10:18:56 AM4/27/23
to ansible...@googlegroups.com
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.

--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages