Team,
I am trying to verify if sdd exists in mount command output. so when there is any, i am fine but when there is none, my task is simply failing instead of just telling me that no mounts exists. any hint how to tackle this? I don't want my task to fail but to report what is the state.
when status code is 0 am good but when status code is 1 am just seeing failure instead of a helpful message that mounds sdd don't exist.
"mount | grep sdd"
- name: "Verify LVP Mounts sdd exists on CPU Nodes for mount_device"
shell: "mount | grep sdd"
register: lvp_mount
ignore_errors: yes
failed_when: False
delegate_to: "{{ item }}"
with_items: "{{ groups['kube-cpu-node'] }}"
- name: "Report status of mounts"
fail:
msg: |
Mounts sdd not found
Output of `mount | grep sdd`:
{{ lvp_mount.stdout }}
{{ lvp_mount.stderr }}
when: lvp_mount | failed
output:
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'lvp_mount | failed' failed. The error was: template error while templating string: no filter named 'failed'. String: {% if lvp_mount | failed %} True {% else %} False {% endif %}\n\nThe error appears to be in '/k8s/baremetal/roles/maglev-services-pre-install-checks/tasks/main.yml': line 111, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n with_items: \"{{ groups['kube-cpu-node'] }}\"\n - name: \"Report status of mounts\"\n ^ here\n"}
expected output:
if lvp_mount.rc == 0
msg: mount sdd exists
if lvp_mount.rc == 1
msg: mount sdd does not exists
if lvp_mount.rc not in [0, 1]
msg: mount exec errir
The error is telling you that there is no filter named failed
. To check for a failed result in a conditional, use this instead:
when: lvp_mount is failed
Alternatively, to check for a successful result, use:
when: lvp_mount is succeeded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With