# iterate over disk devices

**URL:** <https://forum.ansible.com/t/iterate-over-disk-devices/14889>\
**Category:** Ansible Project\
**Created:** [March 29, 2014, 3:41am UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889 "2014-03-29T03:41:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 29, 2014, 3:41am UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889/1 "2014-03-29T03:41:02Z")

</div>

Hi all,

Is there a way how ti easily iterate over facter\_blockdevices?

Example:

- name: checking disks for failure  
command: /usr/sbin/smartctl /dev/{{ item }}  
with\_items: facter\_blockdevices  
register: smart\_out

Facts:  
“facter\_blockdevices”: “sda,sdb,sdc,sdd,sde,sdf”,

Thanks!

Filip

---

<div class="post-metadata">

**Author:** ![Veroslav\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Veroslav\_Kaplan](https://forum.ansible.com/u/Veroslav_Kaplan)\
**Post date:** [March 29, 2014, 12:54pm UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889/2 "2014-03-29T12:54:38Z")

</div>

Ahoj Filip,

I would consider separating facter\_blockdevices fact to a list. ( see [https://gist.github.com/VerosK/9853931](https://gist.github.com/VerosK/9853931) ).

I don’t now if this is the right Ansible-way, but at least it works.

–Věroš

---

<div class="post-metadata">

**Author:** ![Paul\_Durivage](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Durivage](https://forum.ansible.com/u/Paul_Durivage)\
**Post date:** [March 31, 2014, 2:28pm UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889/3 "2014-03-31T14:28:11Z")

</div>

Hi Filip,

You’ll find that calling the split method on the string works.

See this Gist: [https://gist.github.com/angstwad/9893480](https://gist.github.com/angstwad/9893480)

---

<div class="post-metadata">

**Author:** ![Filip\_Slunecko](https://avatars.discourse-cdn.com/v4/letter/f/58956e/32.png) [@Filip\_Slunecko](https://forum.ansible.com/u/Filip_Slunecko)\
**Post date:** [March 31, 2014, 6:04pm UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889/4 "2014-03-31T18:04:32Z")

</div>

Thank you!

I tried jinja filters and they do not work :).  
I assume I can use any python function there right?

---

<div class="post-metadata">

**Author:** ![Paul\_Durivage](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Paul\_Durivage](https://forum.ansible.com/u/Paul_Durivage)\
**Post date:** [March 31, 2014, 6:22pm UTC](https://forum.ansible.com/t/iterate-over-disk-devices/14889/5 "2014-03-31T18:22:57Z")

</div>

Hi Filip,

No problem!

No, not every Python function is available in Jinja. In that example, you see we can use any method associated with string in Jinja, because the string is still an object, and it’s methods come with it. Just remember that you always have access to the objects methods.

For future reference, by the way, the list of standard Jinja filters are here: [http://jinja.pocoo.org/docs/templates/#builtin-filters](http://jinja.pocoo.org/docs/templates/#builtin-filters)  
I’m actually not sure if all the Ansible filters are documented in a single place, but IIRC they are all in the following Python file:  
[https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/filter\_plugins/core.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/filter_plugins/core.py)
