ansible shell 任务在没有正确消息的情况下出错

ansible shell task erroring out without proper message

团队,

我正在尝试验证 sdd 是否存在于 mount 命令输出中。所以当有任何东西时,我很好但是当有 none 时,我的任务只是失败而不是仅仅告诉我没有安装存在。任何提示如何解决这个问题?我不希望我的任务失败,而是要报告状态。

当状态代码为 0 时很好,但是当状态代码为 1 时只是看到失败而不是提示 sdd 不存在的有用消息。

 "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

输出:

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"}

预期输出:

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

错误告诉您没有名为 failed 的过滤器。要检查条件中的失败结果,请改用此方法:

when: lvp_mount is failed

或者,要检查结果是否成功,请使用:

when: lvp_mount is succeeded