How to define "all hosts but first in a group"?

Hello, Ansible experts.
I’m stuck with this and I need help.

I have several servers in a group in inventory file.
[webservers] web1 web2 web3 web4 . .

And I want to do some tasks to all hosts except first one in webservers group.
Unworkable pattern follows. :frowning:

`

  • name: do something all hosts but first in a webservers group
    hosts: webservers[1:last]
    tasks:
    (snip)
    `

Since I can’t fix how many hosts webservers group has, I want to make it rather dynamic.
Any suggestion?

Can’t check if it works, but Python’s way to say “all but first” is some_list[1:]. So I’d guess you want with_items: groups.webservers[1:]

t goto tomoyan777@gmail.com napisał:

Thanks Mr.Tomasz
I tried with following target, but it didn’t work :frowning:

`

  • name: do something all hosts but first in a webservers group
    hosts: webservers[1:]
    tasks:
    (snip)
    `

Just “no host matched” and skipped.

Hello,

I have several servers in a group in inventory file.
[webservers]
web1
web2
web3
web4
.

Please, try this way:

- name: do something all hosts but first in a webservers group
  hosts: webservers[1:last]
  tasks:

hosts: webservers:!web1

`

  • hosts: webservers:!webservers[0]
    `

Should do the trick. This means include all the webservers except the first one.

  • James