Loop through a group of hosts with pattern

Hi everyone!

I’m thinking of looping through all the hosts from a playbook with a pattern. I have this play:

`

  • hosts: localhost # Select all hosts
    tasks:
  • name: Debug the list
    debug:
    msg: “host: {{ item }}”
    with_items: “{{groups.all}}”

`

I wanted something like this:

`

  • hosts: localhost # Select all hosts EXCEPT localhost
    tasks:
  • name: Debug the list
    debug:
    msg: “host: {{ item }}”
    with_items: “{{ groups.all:!localhost }}”

`

I tried but I got an error:

`

fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “template error while templating string: expected token ‘end of print statement’, got ‘:’. String: {{groups.all:!localhost}}”}

`

Check out with_inventory_hostnames

http://docs.ansible.com/ansible/playbooks_loops.html#looping-over-the-inventory

SWEET! Thanks mate!