Hi,
Many thanks for these ideas, since this posting was held back for 
moderation (it was my first one in this group) I asked the question on irc 
channel and got the tip: simply write a filter to collect the necessary 
data to a list which can be summed up."ktosiek" from irc channel wrote me 
the start of a filter which I modified to solve my problem :D

this is the Filter:

def multiget(dictionary, keys):
    return [int(dictionary[k]['xm_infos']['free_memory']) for k in keys]

which can then be used in a playbook like this:
    - name: show the sum
      debug: msg="{{ hostvars | multiget(keys=groups.Cluster)|sum }}"

The first Idea was to have the filter more generally to use it like this:
debug: msg="{{ hostvars | 
multiget(keys=groups.Cluster)|sum(attribute=xm_infos.free_memory) }}"
But the values inside the list must be casted to int and I had no other 
Idea than to do this inside the generation of the list. 

 
Cheers
     Ulli

PS: I like ansible more and more especially the really cool and helpfull 
community ;-D

Am Sonntag, 4. Januar 2015 02:02:04 UTC+1 schrieb Ulrich Hochholdinger:
>
> 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/c9fd6ee7-f328-4680-a876-0d9da8c8469c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to