Search code examples
ansibleansible-inventory

Can I trigger a play for hosts not in a specific group?


I would like take two different provisioning actions for hosts in and not in a specific group. For example:

- hosts: nis_server
  tasks:
  - name: Set up NIS server

- hosts: ~nis_server
  tasks:
  - name: Use NIS server for authentication & login

Is there a syntax/operator to invert a group without having to manually/scriptually create a complement group?

Note: I tried using the ~ syntax above, surprisingly ansible actually accepts this, but simply ignores the tilde, so ~nis_server is the same as nis_server.


Solution

  • Please check patterns documentation: all:!nis_server.