# Sum a list of items received

**URL:** <https://forum.ansible.com/t/sum-a-list-of-items-received/32342>\
**Category:** Ansible Project\
**Created:** [February 27, 2020, 2:36pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342 "2020-02-27T14:36:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [February 27, 2020, 2:36pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/1 "2020-02-27T14:36:20Z")

</div>

I’m using the gluster\_heal\_info module to check the heal status of a gluster volume. What I’d like to do is gather the “no\_of\_entries” parameter, sum them up, and it if it is 0, move to the next step of stopping gluster on that server, update it, and restart the service. The playbook below is my initial test to see how to grab that information. It is giving me the following error:

[root@test-server ~]#ansible-playbook gluster\_heal\_info.yml --limit [storage1.tc.secure-ose.faa.gov](http://storage1.tc.secure-ose.faa.gov) -K  
BECOME password:

PLAY [gluster] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Find out the healing status of /home] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [gluster1]

TASK [set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [gluster1]: FAILED! =\> {“msg”: “Unexpected templating type error occurred on ({{ home\_heal\_status.glusterfs.heal\_info | sum(attribute=‘no\_of\_entries’, start=) }}): can only concatenate list (not "AnsibleUnsafeText") to list”}

I’m not too familiar with jinja2 templates yet, so I’m sure I’m not doing something correct. Can anyone point me in the right direction?

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![Daniel\_Whitley1](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@Daniel\_Whitley1](https://forum.ansible.com/u/Daniel_Whitley1)\
**Post date:** [February 27, 2020, 5:48pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/2 "2020-02-27T17:48:32Z")

</div>

Hey Harry-  
I saw this over my lunch break and thought I’d ask if it really matters (meaning, do you use it later or something) what the count/sum is or if you just want to wait until something is true (such as the number of “heals” is 0). If the count doesn’t really matter, I wonder if you could take advantage of [until](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#retrying-a-task-until-a-condition-is-met) in your “Find out the healing status of /home” task? It looks like the [gluster\_heal\_info](https://docs.ansible.com/ansible/latest/modules/gluster_heal_info_module.html) module returns a list of files in “heal\_info” so you may just want to wait “until” that list is empty before moving on to the next task? I’ve not tried this nor ever used the module. I also realize it doesn’t address the question you asked, but you should be used to that from me at this point. 🙂  
-Daniel

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [February 27, 2020, 6:44pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/3 "2020-02-27T18:44:05Z")

</div>

Hey Daniel! This stem from ticket #02582900. Since the stance from Support is “we don’t debug playbooks”, I care here.

Their suggestion was to make sure that no healing operation was going on, stop Gluster, do the “yum update “, then restart Gluster & move to the next server.

So what I’m trying to accomplish is start with server1, wait for any healing operations on our 3 volumes to finish, stop/update/start then move to the next. I’m sure this will lead to a “workflow template” discussion/approach, but right now this is my starting point.

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [March 2, 2020, 2:29pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/4 "2020-03-02T14:29:53Z")

</div>

So to follow up on this: I looked at this further, and while the gluster\_heal\_info module DOES return a heal\_info list, its not a list of files. It returns the value of every brick (brick name, number of entries, and stattus):

“heal\_info”: [  
{  
“brick”: " server1:/gluster\_bricks/brick3/1",  
“no\_of\_entries”: “0”,  
“status”: “Connected”  
},  
{  
“brick”: " server2:/gluster\_bricks/brick4/1",  
“no\_of\_entries”: “0”,  
“status”: “Connected”  
}  
]

So what I think I need to do is to get the “no\_of\_entries” value from every brick and sum them up. If the sum is zero, I can continue on. If the sum is greater than zero, then there is a heal in process, and I need to wait until that is finished before continuing. That’s the part I’m getting stuck on. Also, if you look at the heal\_info list, the bricks are ALL bricks associated with the gluster volume, which is across all gluster servers. So would it be safe to assume that if the sum is zero, then there is no healing occuring on any server, and the continue-on procedure is to stop gluster on all servers, update them, then restart gluster?

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![Daniel\_Whitley](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Daniel\_Whitley](https://forum.ansible.com/u/Daniel_Whitley)\
**Post date:** [March 2, 2020, 4:47pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/5 "2020-03-02T16:47:49Z")

</div>

Hey Harry-  
That’s insightful information about heal\_info actually being a list of dicts. With that being said, while you CAN create a sum (one such way is something like {{ heal\_info | map(attribute=‘no\_of\_entries’) | map(‘int’) | sum() }}), I still question if that is truly necessary. It sounds to me as if all you care about is waiting [until](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#retrying-a-task-until-a-condition-is-met) no\_of\_entries is 0 for every brick. Using your initial task, I wonder if this untested pseudo-code could be modified for your needs:

- name: Find out the healing status of /home  
gluster\_heal\_info:  
name: home  
status\_filter: self-heal  
register: home\_heal\_status

until: home\_heal\_status.glusterfs.heal\_info | selectattr(‘no\_of\_entries’,‘ne’,‘0’) | list | count == 0  
retries: 5  
delay: 10

Hopefully this is helpful.  
-Daniel

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [March 2, 2020, 9:26pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/6 "2020-03-02T21:26:28Z")

</div>

Is there a “not equal to” jinja filter? All of the documentation I find shows there’s an ‘equalto’ but I can’t seem to find any “no equalto” equivalent. Even a greater than would work but I can’t find anything like that either.

Harry

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 2, 2020, 9:40pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/7 "2020-03-02T21:40:44Z")

</div>

There is not a "not equal to" filter or an "equalto" filer.  
But you have a "not equal to" \_test\_  
[https://jinja.palletsprojects.com/en/2.10.x/templates/#ne](https://jinja.palletsprojects.com/en/2.10.x/templates/#ne)  
As used in Daniels example

and an "equal to" \_test\_  
[https://jinja.palletsprojects.com/en/2.10.x/templates/#eq](https://jinja.palletsprojects.com/en/2.10.x/templates/#eq)

Greater then \_test\_ is called gt  
[https://jinja.palletsprojects.com/en/2.10.x/templates/#gt](https://jinja.palletsprojects.com/en/2.10.x/templates/#gt)

All the \_tests\_ is here  
[https://jinja.palletsprojects.com/en/2.10.x/templates/#list-of-builtin-tests](https://jinja.palletsprojects.com/en/2.10.x/templates/#list-of-builtin-tests)

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [March 3, 2020, 12:53pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/8 "2020-03-03T12:53:59Z")

</div>

Well, I’m obviously completely misunderstanding something. Here’s what the playbook looks like:

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [March 3, 2020, 1:36pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/9 "2020-03-03T13:36:50Z")

</div>

Hi,

> Well, I'm obviously completely misunderstanding something. Here's  
> what the playbook looks like:  
> [...]  
> fatal: [server1]: FAILED! =\> {"msg": "The conditional check  
> 'home\_heal\_status.glusterfs.heal\_info |  
> selectattr('no\_of\_entries','ne','0') | list | count == 0' failed. The  
> error was: no test named 'ne'"}
> 
> Sure looks like 'ne' doesn't exist to me!

you might have an older Jinja2 version installed. IIRC the 'ne' test  
was not present in every version.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [March 3, 2020, 2:14pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/10 "2020-03-03T14:14:34Z")

</div>

My system is RHEL 7.7. The version of jinja2 is 2.7.2 and there isn’t a newer version available:

[root@server1 ~]#rpm -qa python-jinja2  
python-jinja2-2.7.2-4.el7.noarch

Harry

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [March 3, 2020, 2:31pm UTC](https://forum.ansible.com/t/sum-a-list-of-items-received/32342/11 "2020-03-03T14:31:28Z")

</div>

I did a “pip install -U jinja2”, then “pip install jinja2”, and it appears to have installed 2.11.1. Now the playbook runs, so that must’ve been it.

Now I need to figure out how to check the other 2 gluster volumes at the same time, then do each gluster server 1 at a time. But that’s another topic that I won’t go into here. Yet.

Thanks,  
Harry
