I am trying to write ansible code to check space on a mount and when it hits below 12% of drive space to fail.
Your create a string as seen in your stdout
You can't expect Ansible to understand this
"/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.
- name: Making sure the /dev drive space
shell: df --output=pcent /dev/xvda | sed -e 1d -e 's/[ %]//g'
register: devdrivespace
failed_when: devdrivespace.stdout | int < 12
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”
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.
devdrivespace.stdout > 40
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