In ansible, how do I specify an exclusion set of hosts in a playbook?

Robert Rapplean asked:

With command line patterns, you can specify patterns like “all,!ntpservers” but I can’t figure out how to specify this in a playbook. I’m regularly running into cases where I have to install a client on all machines except the server.

My answer:

You specify the hosts for a playbook on the line that begins with hosts:.

From the documentation:

The hosts line is a list of one or more groups or host patterns, separated by colons, as described in the Working with Patterns documentation.

For example:

- hosts: all,!ntpservers
    # ... your tasks here
    # ... etc etc etc

These roles and tasks will be appled to all hosts except ntpservers.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.