# New to ansible and development

**URL:** <https://forum.ansible.com/t/new-to-ansible-and-development/31636>\
**Category:** Ansible Project\
**Created:** [November 11, 2019, 4:31pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636 "2019-11-11T16:31:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [November 11, 2019, 4:31pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636/1 "2019-11-11T16:31:00Z")

</div>

I am trying to write ansible code to check space on a mount and when it hits below 12% of drive space to fail.

---

<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:** [November 11, 2019, 5:17pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636/2 "2019-11-11T17:17:56Z")

</div>

Your create a string as seen in your stdout  
You can't expect Ansible to understand this  
&nbsp;&nbsp;"/dev/xvda2 11% drive spaced is used" \< 12

You need to create an output that only have a number. But because stdout is a  
string you need to filter with int.  
So something like this should work.

&nbsp;&nbsp;- name: Making sure the /dev drive space  
&nbsp;&nbsp;&nbsp;&nbsp;shell: df --output=pcent /dev/xvda | sed -e 1d -e 's/[%]//g'  
&nbsp;&nbsp;&nbsp;&nbsp;register: devdrivespace  
&nbsp;&nbsp;&nbsp;&nbsp;failed\_when: devdrivespace.stdout | int \< 12

---

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [November 11, 2019, 5:53pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636/3 "2019-11-11T17:53:26Z")

</div>

Thanks for replying and your time !! I am still trying to figure out. If the IT seems when I use the \< and pick a number it always fails. If i chose failed\_when: “devdrivespace.stdout \> 12” It does not fail… Just let’s say I want this to fail if there is less then 60% drive space less available.

Would I write it failed\_when: “devdrivespace.stdout \< 40” or

failed\_when: “devdrivespace.stdout \> 80”

---

<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:** [November 11, 2019, 6:05pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636/4 "2019-11-11T18:05:55Z")

</div>

df percent show how much disk space is used, so if you want it to fail when  
available space is less than 60% that would be 40% or more space used.  
&nbsp;&nbsp;devdrivespace.stdout \> 40

---

<div class="post-metadata">

**Author:** ![evnflow](https://avatars.discourse-cdn.com/v4/letter/e/a4c791/32.png) [@evnflow](https://forum.ansible.com/u/evnflow)\
**Post date:** [November 11, 2019, 6:40pm UTC](https://forum.ansible.com/t/new-to-ansible-and-development/31636/5 "2019-11-11T18:40:40Z")

</div>

Kai,

Thank you I going to try to test now by filing up that space! I will have to study up on the sed command I do not know how to use it like you did 🙂

Thanks again! Hopefully, I start picking up ansible
