for loops in Jinja2 can't be used (with any definition of sanity) in
Ansible playbooks.

They can be used in templates used by the template module.

Let's step back a moment...

Can you remove the recursive reference and just call it "actual_free_mem"
or something, and see where you are from there.






On Mon, Jan 5, 2015 at 8:48 AM, Tom Bamford <[email protected]> wrote:

> Hi Ulrich
>
> How about a ‘for’ loop (in Jinja2) contained as a parameter to the
> set_fact module, iterating the facts you gathered as presented in the {{
> hostvars }} magic variable?
>
> Regards
> Tom
>
> On 4 January 2015 at 03:02, Ulrich Hochholdinger <
> [email protected]> wrote:
>
> Hi,
>> I just started playing around with ansible and tried to achieve a simple
>> operations task with it:
>>
>> Iterate over all nodes of my Xen-Cluster -- get free_memory of every node
>> and sum up those values.
>> next step would be making a decision e.g. spawning a new VM without
>> overprovisioning the cluster.
>>
>> So I wrote a simple module which collects "xm info" values as
>> ansible_facts. This was easy...
>>
>> Next step: write a playbook which sums up one of the collected fact
>> (free_memory) -- here I got stuck and have no more ideas how to solve
>> this...
>>
>> This is a not working idea:
>>
>> # vim:ft=ansible:
>> ---
>> - hosts: Cluster
>>   vars:
>>  # should be initially set to zero??
>>     sum_free_memory: "{{ sum_free_memory|int + xm_infos.free_memory|int
>> }}"
>>   tasks:
>>     - name: gather xen facts
>>       xm_info:
>>
>>     - name: show free_memory on host
>>       debug: msg="{{ xm_infos.free_memory|int }}"
>>
>>     - name: increment sum_free_memory
>>       debug: msg="{{ sum_free_memory|int }}"
>>
>> => which obviously doesn't work:
>> ERROR: recursive loop detected in template string: {{ sum_free_memory|int
>> + xm_infos.free_memory|int }}
>>
>> So how can I sum up collected facts from more than one host?
>>
>> Cheers
>>       Ulli
>>
>>
>>  --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/85495348-c277-40f4-ac7a-bade124f02c6%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/85495348-c277-40f4-ac7a-bade124f02c6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> ​
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAAnNz0PREA8CCG-n0cvb%3DQMmOfXoWWBvocG%3D0KURMPFf73JqeA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAAnNz0PREA8CCG-n0cvb%3DQMmOfXoWWBvocG%3D0KURMPFf73JqeA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgz%3DtoZ%3D0zWtcgz49Mi86BKqUQ%3D9_eAX0vZQ-6izgKBMeA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to