gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:35:30 45 4
gpt4 key购买 nike

团队,

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

当状态代码为 0 am 时很好,但当状态代码为 1 am 时只是看到失败,而不是一条有用的消息,即 mounds 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

关于ansible shell 任务在没有正确消息的情况下出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59058694/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com