t_goto
(t goto)
1
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.
`
- 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ł:
t_goto
(t goto)
3
Thanks Mr.Tomasz
I tried with following target, but it didn’t work
`
- name: do something all hosts but first in a webservers group
hosts: webservers[1:]
tasks:
(snip)
`
Just “no host matched” and skipped.
`
- hosts: webservers:!webservers[0]
`
Should do the trick. This means include all the webservers except the first one.