Nusenu1
(Nusenu)
February 18, 2015, 10:15pm
1
Hi,
(this email was previously send to the incorrect list [1])
I've got 3 sets of data:
foo: [ A, B, C, D, ...]
bar: [ 1, 2 ]
tra: [ a, b ]
foo should be combined with bar and tra in a nested loop, but bar and
tra should loop together.
something like (not actually working):
- debug: msg="{{ item[0] }} {{ item[1][0] }} {{ item[1][1] }}
with_netsted:
- foo
- item
with_together:
- bar
- tra
Expected output:
A1a
A2b
B1a
B2b
C1a
C2b
...
How would I actually combine with_nested: and with_together?
In addition to that I will need a loop termination once it reached a
certain amount of loop executions.
On a simple loop I would use 'with_indexed_items:' and check the index
against a given max value. How would that loop count limit be
implemented in the loop described above?
thanks!
Nusenu
[1] https://groups.google.com/d/msg/ansible-devel/aLrH_SC8HyY/FZPs7GanHysJ
Nusenu1
(Nusenu)
February 19, 2015, 6:25pm
2
I got it working. I combined 'bar' and 'tra' in a dictionary and used
that in with_nested
Now I'm left with the question: How can I limit the amount of loops in
a with_nested loop?
Nusenu1
(Nusenu)
March 16, 2015, 8:29pm
3
How can I limit the amount of loops in a with_nested loop?
I still didn't find a solution for this. Maybe someone can suggest
alternative approaches if the use case is clear:
I've got two use cases where I would need an index counter within a
with_nested loop (or any other solution that gets the job done):
1) limit number of service instances based on available machine memory
basically something like:
create process instances
with_nested:
- set1
- set2
when: machine_memory / loopIndex+1 > minimalmemoryrequired
but there is no "loopIndex" that I could use..
2) assign unique TCP port to a service to prevent duplicate bindings
here is the ansible role where this would be useful for me:
https://github.com/nusenu/relayor/blob/master/tasks/configure.yml
thanks,
Nusenu