Loop through a group of hosts with pattern

181 views
Skip to first unread message

jzarzoso

unread,
May 19, 2016, 10:29:50 PM5/19/16
to Ansible Project
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}}"}



Matt Martz

unread,
May 19, 2016, 10:48:42 PM5/19/16
to ansible...@googlegroups.com
Check out with_inventory_hostnames

--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8f8c3e61-f670-45d5-879e-9cdb781afab6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

jzarzoso

unread,
May 19, 2016, 10:56:42 PM5/19/16
to Ansible Project
SWEET! Thanks mate!


On Friday, May 20, 2016 at 10:48:42 AM UTC+8, Matt Martz wrote:
Check out with_inventory_hostnames

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}}"}



--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages