# How to save an array of facts using a debug: msg and with\_sequence?

**URL:** <https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [July 30, 2019, 5:45pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907 "2019-07-30T17:45:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Rios](https://avatars.discourse-cdn.com/v4/letter/g/bc79bd/32.png) [@Gabriel\_Rios](https://forum.ansible.com/u/Gabriel_Rios)\
**Post date:** [July 30, 2019, 5:45pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907/1 "2019-07-30T17:45:37Z")

</div>

Hi,

The following are facts from win\_pagefile query. From these, I want to retrieve the “maximum\_size” fact of every element in the “pagefiles” array, then subtract the “initial\_size” fact and divide that by 1024 in order to get every pagefile disk (in GB) to help automate a report on windows servers.

First, I am attempting to get only the “maximum\_size” fact of every element in the array. Below are attempts at retrieving this fact using the with\_sequence loop…wthout success. Please, help me to review which syntax would work or if there’s any other way. I’d be really grateful.

ok: [10.240.30.249] =\> {  
“win\_pf”: {  
“automatic\_managed\_pagefiles”: false,  
“changed”: false,  
“failed”: false,  
“pagefiles”: [  
{  
“caption”: “c:\ ‘pagefile.sys’”,  
“description”: “‘pagefile.sys’ @ c:\”,  
“initial\_size”: 0,  
“maximum\_size”: 0,  
“name”: “c:\pagefile.sys”  
},  
{  
“caption”: “e:\ ‘pagefile.sys’”,  
“description”: “‘pagefile.sys’ @ e:\”,  
“initial\_size”: 3583,  
“maximum\_size”: 9133,  
“name”: “e:\pagefile.sys”  
}  
]  
}  
}

Below there are a number of ways I have tried:

---

<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:** [July 30, 2019, 6:33pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907/2 "2019-07-30T18:33:45Z")

</div>

There is no need to use with\_sequence you can just use win\_pf with with\_items directly.

&nbsp;&nbsp;- debug: msg="{{ (item.maximum\_size - item.initial\_size) / 1024 }}"  
&nbsp;&nbsp;&nbsp;&nbsp;with\_items: "{{ win\_pf.pagefiles }}"

---

<div class="post-metadata">

**Author:** ![Gabriel\_Rios](https://avatars.discourse-cdn.com/v4/letter/g/bc79bd/32.png) [@Gabriel\_Rios](https://forum.ansible.com/u/Gabriel_Rios)\
**Post date:** [July 30, 2019, 8:08pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907/3 "2019-07-30T20:08:28Z")

</div>

This gives me 2 values:

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.240.30.249] =\> (item={u’caption’: u"c:\ ‘pagefile.sys’“, u’maximum\_size’: 0, u’initial\_size’: 0, u’description’: u”‘pagefile.sys’ @ c:\“, u’name’: u’c:\pagefile.sys’}) =\> {  
“msg”: “0.0”  
}  
ok: [10.240.30.249] =\> (item={u’caption’: u"e:\ ‘pagefile.sys’”, u’maximum\_size’: 9133, u’initial\_size’: 3583, u’description’: u"‘pagefile.sys’ @ e:\", u’name’: u’e:\pagefile.sys’}) =\> {  
“msg”: “5.419921875”  
}

How can I store them in 1 variable using set\_fact?

---

<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:** [July 30, 2019, 8:28pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907/4 "2019-07-30T20:28:56Z")

</div>

There are many ways to store a value in a vaiable, if there is a list you are after something like this should work.

&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myvar: '{{ myvar | default() + [(item.maximum\_size - item.initial\_size) / 1024] }}'  
&nbsp;&nbsp;&nbsp;&nbsp;with\_items: "{{ win\_pf.pagefiles }}"

---

<div class="post-metadata">

**Author:** ![Gabriel\_Rios](https://avatars.discourse-cdn.com/v4/letter/g/bc79bd/32.png) [@Gabriel\_Rios](https://forum.ansible.com/u/Gabriel_Rios)\
**Post date:** [July 31, 2019, 5:30pm UTC](https://forum.ansible.com/t/how-to-save-an-array-of-facts-using-a-debug-msg-and-with-sequence/30907/5 "2019-07-31T17:30:46Z")

</div>

Thanks a lot. Already tested it and it works perfectly.
