Is the following ansible documentation incorrect? "the first 10: --limit boston[1:10]". Shouldn't it be "--limit boston[0:9]"

23 views
Skip to first unread message

Mike Cavedon

unread,
Feb 1, 2018, 4:49:06 PM2/1/18
to Ansible Project
I'm seeing what appears to be two different definitions of how limits work. There is the first one here:


What about just the first 10, and then the next 10?:

ansible-playbook -i production webservers.yml --limit boston[1:10]
ansible-playbook -i production webservers.yml --limit boston[11:20]

Then there appears to be a different definition here:


You can select a host or subset of hosts from a group by their position. For example, given the following group:

[webservers]
cobweb
webbing
weber

You can refer to hosts within the group by adding a subscript to the group name:

webservers[0]       # == cobweb
webservers[-1]      # == weber
webservers[0:1]     # == webservers[0],webservers[1]
                    # == cobweb,webbing
webservers[1:]      # == webbing,weber

Is it "--limit boston[1:2], or "--limit webservers[0:1]" for the first 2?

Kai Stian Olstad

unread,
Feb 1, 2018, 5:06:58 PM2/1/18
to ansible...@googlegroups.com
On Thursday, 1 February 2018 22.49.06 CET Mike Cavedon wrote:
> I'm seeing what appears to be two different definitions of how limits work.
> There is the first one here:
>
> http://docs.ansible.com/ansible/latest/playbooks_best_practices.html
>
> What about just the first 10, and then the next 10?:
>
> ansible-playbook -i production webservers.yml --limit boston[1:10]
> ansible-playbook -i production webservers.yml --limit boston[11:20]

This is not correct so it a documentation bug.
To make the statement correct it should be boston[0:9] and boston[10:19]


> Then there appears to be a different definition here:
>
> http://docs.ansible.com/ansible/latest/intro_patterns.html
>
> You can select a host or subset of hosts from a group by their position.
> For example, given the following group:
>
> [webservers]
> cobweb
> webbing
> weber
>
> You can refer to hosts within the group by adding a subscript to the group
> name:
>
> webservers[0] # == cobweb
> webservers[-1] # == weber
> webservers[0:1] # == webservers[0],webservers[1]
> # == cobweb,webbing
> webservers[1:] # == webbing,weber

This is correct.


> Is it "--limit boston[1:2], or "--limit webservers[0:1]" for the first 2?

"--limit webservers[0:1]"


--
Kai Stian Olstad

Mike Cavedon

unread,
Feb 1, 2018, 5:38:42 PM2/1/18
to Ansible Project
I entered a PR to correct the bug. thanks again

Brian Coca

unread,
Feb 6, 2018, 10:27:33 AM2/6/18
to Ansible Project
Also you have to distinguish between 'array slices' and 'name ranges':

i.e:

[webservers]
one
two
three
other[1:23]


So webservers[1:3] is a list slice, while other[12:21] is actually a
range of host names




--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages