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?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0503bf57-3ad5-43cc-babd-ad94b48bd9c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tomasz Kontusz at Nov 19, 2014 at 8:45 am
    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ł:
    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?

    --
    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.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/ansible-project/0503bf57-3ad5-43cc-babd-ad94b48bd9c7%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    Wysłane za pomocą K-9 Mail.

    --
    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.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9e392d67-95ff-4e99-b49a-b236cdc8029a%40email.android.com.
    For more options, visit https://groups.google.com/d/optout.
  • T goto at Nov 19, 2014 at 9:09 am
    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.

    --
    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.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d238dd67-322a-41d1-b99c-51cc418b1d8e%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Bohdan Sydor at Nov 19, 2014 at 9:14 am
    On Wed, Nov 19, 2014 at 9:28 AM, t goto wrote:


    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

    --
    Regards,
    Bohdan

    --
    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.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CALtFRBiKkGE_yJqUZoZg%3Dwd0Qbe3_29RetXqOzA4DQnUEsvpcw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Martin at Nov 19, 2014 at 2:48 pm
    - hosts: webservers:!webservers[0]

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

    - James



    On Wednesday, November 19, 2014 4:14:35 AM UTC-5, Bohdan Sydor wrote:

    On Wed, Nov 19, 2014 at 9:28 AM, t goto <tomoy...@gmail.com <javascript:>>
    wrote:


    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

    --
    Regards,
    Bohdan
    --
    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.
    To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f70fb7b7-1927-478b-a867-d13354fc7a88%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedNov 19, '14 at 8:28a
activeNov 19, '14 at 2:48p
posts5
users4

People

Translate

site design / logo © 2019 Grokbase